#include <bits/stdc++.h>
using namespace std;
const long long BE = 1ll << 50;
const int N = 1e5 + 5;
int n, m, a[N], lgn, i, j;
int bi[N];
inline void add(int x) {
  for (; x <= n; x += x & -x) --bi[x];
}
inline int ask1(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += bi[x];
  return ans;
}
inline int ask2(int k) {
  int i = 0, j = lgn, ni;
  for (; j >= 0; --j)
    if (ni = i + (1 << j), ni < n && bi[ni] < k) k -= bi[ni], i = ni;
  return i + 1;
}
struct que {
  long long k;
  int x, i;
} qu[N];
long long kk[N], ans[N];
int xx[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (; 1 << lgn + 1 < n; ++lgn)
    ;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> qu[i].x >> qu[i].k, qu[i].i = i;
  sort(qu + 1, qu + m + 1,
       [&](const que& a, const que& b) { return a.x < b.x; });
  long long z = BE, step = 0;
  for (i = 1; i <= n; ++i) bi[i] = i & -i;
  for (i = m, j = n; i; --i) {
    auto opt = [&](long long id, int tp) {
      long long ns = z <= id ? 0 : (z - id + j - 1) / j;
      z -= j * ns;
      step += ns;
      int ret = ask2(id - z + 1);
      if (tp == 1) add(ret);
      return ret;
    };
    for (; j && a[j] > qu[i].x; opt(a[j], 1), --j)
      ;
    if (a[1] > qu[i].x)
      kk[qu[i].i] = 0, ans[qu[i].i] = qu[i].x;
    else
      xx[qu[i].i] = opt(qu[i].x, 0), kk[qu[i].i] = step - qu[i].k;
  }
  for (i = 1; i <= m; ++i) qu[i] = (que){kk[i], xx[i], i};
  sort(qu + 1, qu + m + 1,
       [&](const que& a, const que& b) { return a.k < b.k; });
  z = BE;
  step = 0;
  for (i = 1; i <= n; ++i) bi[i] = i & -i;
  for (i = 1; i <= m && qu[i].k == 0; ++i)
    ;
  for (j = n; j; --j) {
    long long ns = (z - a[j] + j - 1) / j;
    for (; i <= m && qu[i].k <= ns + step; ++i)
      ans[qu[i].i] = z - (qu[i].k - step) * j + ask1(qu[i].x) - 1;
    z -= j * ns;
    step += ns;
    add(ask2(a[j] - z + 1));
  }
  for (i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}

### Prompt

Please create a solution in Cpp to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long BE = 1ll << 50;
const int N = 1e5 + 5;
int n, m, a[N], lgn, i, j;
int bi[N];
inline void add(int x) {
  for (; x <= n; x += x & -x) --bi[x];
}
inline int ask1(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += bi[x];
  return ans;
}
inline int ask2(int k) {
  int i = 0, j = lgn, ni;
  for (; j >= 0; --j)
    if (ni = i + (1 << j), ni < n && bi[ni] < k) k -= bi[ni], i = ni;
  return i + 1;
}
struct que {
  long long k;
  int x, i;
} qu[N];
long long kk[N], ans[N];
int xx[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (; 1 << lgn + 1 < n; ++lgn)
    ;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> qu[i].x >> qu[i].k, qu[i].i = i;
  sort(qu + 1, qu + m + 1,
       [&](const que& a, const que& b) { return a.x < b.x; });
  long long z = BE, step = 0;
  for (i = 1; i <= n; ++i) bi[i] = i & -i;
  for (i = m, j = n; i; --i) {
    auto opt = [&](long long id, int tp) {
      long long ns = z <= id ? 0 : (z - id + j - 1) / j;
      z -= j * ns;
      step += ns;
      int ret = ask2(id - z + 1);
      if (tp == 1) add(ret);
      return ret;
    };
    for (; j && a[j] > qu[i].x; opt(a[j], 1), --j)
      ;
    if (a[1] > qu[i].x)
      kk[qu[i].i] = 0, ans[qu[i].i] = qu[i].x;
    else
      xx[qu[i].i] = opt(qu[i].x, 0), kk[qu[i].i] = step - qu[i].k;
  }
  for (i = 1; i <= m; ++i) qu[i] = (que){kk[i], xx[i], i};
  sort(qu + 1, qu + m + 1,
       [&](const que& a, const que& b) { return a.k < b.k; });
  z = BE;
  step = 0;
  for (i = 1; i <= n; ++i) bi[i] = i & -i;
  for (i = 1; i <= m && qu[i].k == 0; ++i)
    ;
  for (j = n; j; --j) {
    long long ns = (z - a[j] + j - 1) / j;
    for (; i <= m && qu[i].k <= ns + step; ++i)
      ans[qu[i].i] = z - (qu[i].k - step) * j + ask1(qu[i].x) - 1;
    z -= j * ns;
    step += ns;
    add(ask2(a[j] - z + 1));
  }
  for (i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}

```