Sum of terms and finding missing terms