#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long n, q, l, r, a[N], pref[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n >> q;
for(int i=1; i<=n; ++i) {
cin >> a[i];
pref[i] = pref[i-1] + a[i];
}
while(q--) {
cin >> l >> r;
cout << pref[r] - pref[l] << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDVlNSArIDU7CmxvbmcgbG9uZyBuLCBxLCBsLCByLCBhW05dLCBwcmVmW05dOwoKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoMCk7CiAgICBjb3V0LnRpZSgwKTsKLy8gICAgZnJlb3BlbigiLmlucCIsICJyIiwgc3RkaW4pOwovLyAgICBmcmVvcGVuKCIub3V0IiwgInciLCBzdGRvdXQpOwogICAgY2luID4+IG4gPj4gcTsKICAgIGZvcihpbnQgaT0xOyBpPD1uOyArK2kpIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICBwcmVmW2ldID0gcHJlZltpLTFdICsgYVtpXTsKICAgIH0KICAgIHdoaWxlKHEtLSkgewogICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgY291dCA8PCBwcmVmW3JdIC0gcHJlZltsXSA8PCAnXG4nOwogICAgfQogICAgcmV0dXJuIDA7Cn0K