#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M, i, tmp, start, end;
vector<int> sum; // sum[i]: i번째 값까지의 합
int now;
cin >> N >> M;
now = 0;
sum.push_back(now);
for (i = 0; i < N; i++) {
cin >> tmp;
now += tmp;
sum.push_back(now);
}
for (i = 0; i < M; i++) {
cin >> start >> end;
cout << sum[end] - sum[start - 1] << "\n";
}
return 0;
}