#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "aib";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif // HOME
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = (int)(1e9) + 7;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;
int N, M;
int AIB[2 * NMAX];
void update(int i, int x) {
for(; i <= N; i += i & (-i))
AIB[i] += x;
}
int query(int i) {
int ans = 0;
for(; i; i -= i & (-i))
ans += AIB[i];
return ans;
}
int bs(int sum) {
int lo = 1, hi = N, mi, q;
while(lo <= hi) {
mi = (lo + hi) / 2;
q = query(mi);
if(q < sum)
lo = mi + 1;
if(q == sum)
return mi;
if(q > sum)
hi = mi - 1;
}
return -1;
}
int main() {
int i, t, x, y;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%d%d", &N, &M);
for(i = 1; i <= N; i++) {
scanf("%d", &x);
update(i, x);
}
while(M--) {
scanf("%d", &t);
if(t == 0) {
scanf("%d%d", &x, &y);
update(x, y);
} else if(t == 1) {
scanf("%d%d", &x, &y);
printf("%d\n", query(y) - query(x - 1));
} else {
scanf("%d", &x);
printf("%d\n", bs(x));
}
}
return 0;
}