Problem: There is a strip with an infinite number of cells. Cells are numbered starting with 0. Initially the cell i contains a ball with the number i.

There are n pockets located at cells a_1, …, a_n. Each cell contains at most one pocket.

Filtering is the following sequence of operations:

  * All pockets at cells a_1, …, a_n open simultaneously, which makes balls currently located at those cells disappear. After the balls disappear, the pockets close again.
  * For each cell i from 0 to ∞, if the cell i contains a ball, we move that ball to the free cell j with the lowest number. If there is no free cell j < i, the ball stays at the cell i.



Note that after each filtering operation each cell will still contain exactly one ball.

For example, let the cells 1, 3 and 4 contain pockets. The initial configuration of balls is shown below (underscores display the cells with pockets):

0 1 2 3 4 5 6 7 8 9 ... 

After opening and closing the pockets, balls 1, 3 and 4 disappear:

0  2  5 6 7 8 9 ... 

After moving all the balls to the left, the configuration looks like this:

0 2 5 6 7 8 9 10 11 12 ... 

Another filtering repetition results in the following:

0 5 8 9 10 11 12 13 14 15 ... 

You have to answer m questions. The i-th of these questions is "what is the number of the ball located at the cell x_i after k_i repetitions of the filtering operation?"

Input

The first line contains two integers n and m — the number of pockets and questions respectively (1 ≤ n, m ≤ 10^5).

The following line contains n integers a_1, …, a_n — the numbers of cells containing pockets (0 ≤ a_1 < … < a_n ≤ 10^9).

The following m lines describe questions. The i-th of these lines contains two integers x_i and k_i (0 ≤ x_i, k_i ≤ 10^9).

Output

Print m numbers — answers to the questions, in the same order as given in the input.

Example

Input

3 15
1 3 4
0 0
1 0
2 0
3 0
4 0
0 1
1 1
2 1
3 1
4 1
0 2
1 2
2 2
3 2
4 2


Output

0
1
2
3
4
0
2
5
6
7
0
5
8
9
10

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000ll;
int n, m, cnt, a[100001], nw, L, Cnt, po;
long long ans[100001], t, l, r, c;
struct node {
  int x, ord;
  long long k;
} q[100001], Q[100001];
struct node2 {
  long long val[400001];
  int siz[400001], l[400001], r[400001];
  void build(int i, int L, int R) {
    l[i] = L;
    r[i] = R;
    siz[i] = R - L + 1;
    if (L == R) {
      val[i] = 1ll * L + inf;
      return;
    }
    int mid = (L + R) >> 1;
    val[i] = 0;
    build(i << 1, L, mid);
    build(i << 1 | 1, mid + 1, R);
  }
  void pushdown(int i) {
    if (!val[i] || l[i] == r[i]) return;
    val[i << 1] += val[i];
    val[i << 1 | 1] += val[i];
    val[i] = 0;
  }
  long long query(int i, int x) {
    pushdown(i);
    if (l[i] == r[i]) return val[i];
    int mid = (l[i] + r[i]) >> 1;
    if (x <= mid) return query(i << 1, x);
    return query(i << 1 | 1, x);
  }
  int find(int i, int x) {
    pushdown(i);
    if (l[i] == r[i]) return l[i];
    if (siz[i << 1] >= x) return find(i << 1, x);
    return find(i << 1 | 1, x - siz[i << 1]);
  }
  void dec(int i, int L, int R, long long v) {
    if (L > R) return;
    pushdown(i);
    if (l[i] == L && r[i] == R) {
      val[i] -= v;
      return;
    }
    int mid = (l[i] + r[i]) >> 1;
    if (R <= mid)
      dec(i << 1, L, R, v);
    else if (L > mid)
      dec(i << 1 | 1, L, R, v);
    else
      dec(i << 1, L, mid, v), dec(i << 1 | 1, mid + 1, R, v);
  }
  void del(int i, int x) {
    pushdown(i);
    if (l[i] == r[i]) {
      val[i] = -1, siz[i] = 0;
      return;
    }
    int mid = (l[i] + r[i]) >> 1;
    if (x <= mid)
      del(i << 1, x);
    else
      del(i << 1 | 1, x);
    siz[i] = siz[i << 1] + siz[i << 1 | 1];
  }
} T;
bool cmpx(node a, node b) { return a.x > b.x; }
bool cmpk(node a, node b) { return a.k < b.k; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    cnt++;
    scanf("%d%I64d", &q[cnt].x, &q[cnt].k), q[cnt].ord = i;
    if (q[cnt].x < a[1] || q[cnt].k == 0) ans[i] = q[cnt].x, cnt--;
  }
  sort(q + 1, q + 1 + cnt, cmpx);
  L = 1;
  t = 0;
  T.build(1, 1, n);
  Cnt = 0;
  nw = n;
  while (L <= cnt) {
    l = T.query(1, T.find(1, 1));
    r = T.query(1, T.find(1, T.siz[1]));
    while (L <= cnt && q[L].x >= l && q[L].x <= r)
      Q[++Cnt].x = T.find(1, q[L].x - l + 1), Q[Cnt].k = t - q[L].k,
      Q[Cnt].ord = q[L].ord, L++;
    if (L > cnt) break;
    while (nw && a[nw] >= l && a[nw] <= r)
      po = T.find(1, a[nw] - l + 1), T.del(1, po), T.dec(1, po + 1, n, 1), nw--,
      r--;
    if (nw && a[nw] > q[L].x)
      po = a[nw];
    else
      po = q[L].x;
    c = (l - po) / nw;
    l -= c * nw;
    r -= c * nw;
    t += c;
    T.dec(1, 1, n, c * nw);
    if (po < l) l -= nw, r -= nw, t++, T.dec(1, 1, n, nw);
  }
  sort(Q + 1, Q + 1 + Cnt, cmpk);
  L = 1;
  t = 0;
  T.build(1, 1, n);
  nw = n;
  while (L <= Cnt) {
    l = T.query(1, T.find(1, 1));
    r = T.query(1, T.find(1, T.siz[1]));
    while (L <= Cnt && Q[L].k == t) ans[Q[L].ord] = T.query(1, Q[L].x), L++;
    if (L > Cnt) break;
    while (nw && a[nw] >= l && a[nw] <= r)
      po = T.find(1, a[nw] - l + 1), T.del(1, po), T.dec(1, po + 1, n, 1), nw--,
      r--;
    if (l - (Q[L].k - t) * nw <= a[nw]) {
      c = (l - a[nw]) / nw;
      l -= c * nw;
      r -= c * nw;
      t += c;
      T.dec(1, 1, n, c * nw);
      if (a[nw] < l) l -= nw, r -= nw, t++, T.dec(1, 1, n, nw);
    } else
      c = Q[L].k - t, l -= c * nw, r -= c * nw, t += c, T.dec(1, 1, n, c * nw);
  }
  for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}