Finding the sum of terms