#include <iostream>
#include <vector>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
vector<ll> aib;
int n, m;
void update(int i, int val) {
for (; i <= n; i+=(i & (-i))) {
aib[i] += val;
}
}
ll take(int i) {
ll sum = 0;
for (; i > 0; i-=(i & (-i))) {
sum += aib[i];
}
return sum;
}
int cb(ll x) {
int st = 1, dr = n;
while (st <= dr) {
int mij = (st + dr) / 2;
if (take(mij) >= x) {
dr = mij - 1;
} else {
st = mij + 1;
}
}
if (st <= n && take(st) == x) {
return st;
}
return -1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fin >> n >> m;
aib.resize(n + 2);
int x;
for (int i = 1; i <= n; i++) {
fin >> x;
update(i, x);
}
while (m--) {
int tip;
fin >> tip;
if (tip == 0) {
int a, b;
fin >> a >> b;
update(a, b);
} else if (tip == 1) {
int a, b;
fin >> a >> b;
fout << take(b) - take(a - 1) << '\n';
} else {
ll a;
fin >> a;
fout << cb(a) << '\n';
}
}
return 0;
}