#include <bits/stdc++.h>
int a[100001], p[100001], N, Q, T[262144];
void build(int p, int l, int r, int w) {
  T[p] = (r - l + 1) * w;
  if (l < r) {
    int m = l + r >> 1;
    build(p << 1, l, m, w);
    build(p << 1 | 1, m + 1, r, w);
  }
}
int get_kth(int k) {
  int p = 1, l = 1, r = N;
  while (l < r) {
    int m = l + r >> 1;
    if (k <= T[p << 1])
      p <<= 1, r = m;
    else
      k -= T[p << 1], p = p << 1 | 1, l = m + 1;
  }
  return l;
}
void P(int x, int w) {
  int p = 1, l = 1, r = N;
  T[p] += w;
  while (l < r) {
    int m = l + r >> 1;
    if (x <= m)
      p <<= 1, r = m;
    else
      p = p << 1 | 1, l = m + 1;
    T[p] += w;
  }
}
struct query_t {
  int x, k, id;
} query[100001];
long long O[100001];
int position, tag;
struct element {
  int times, ord, id;
  inline bool operator<(const element &a) const { return times > a.times; }
};
std::priority_queue<element> queue;
int G(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return T[p];
  int m = l + r >> 1;
  if (R <= m) return G(p << 1, l, m, L, R);
  if (L > m) return G(p << 1 | 1, m + 1, r, L, R);
  return G(p << 1, l, m, L, R) + G(p << 1 | 1, m + 1, r, L, R);
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= N; i++) scanf("%d", a + i);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &query[i].x, &query[i].k);
    query[i].id = i;
  }
  for (int i = 2; i <= N; i++) p[i] = (p[i - 1] + a[i] - a[i - 1]) % (i - 1);
  build(1, 1, N, 1);
  for (int i = N; i; i--) {
    p[i] = get_kth(p[i] + 1);
    P(p[i], -1);
  }
  std::sort(query + 1, query + Q + 1,
            [](const query_t &a, const query_t &b) { return a.x < b.x; });
  int cur_q = 1;
  while (cur_q <= Q && query[cur_q].x < a[1]) {
    O[query[cur_q].id] = query[cur_q].x;
    cur_q++;
  }
  build(1, 1, N, 0);
  for (int i = 1; i < N; i++) {
    P(p[i], 1);
    if (i == 1)
      position = a[2] - 1;
    else {
      int steps = (a[i + 1] - 1 - position) / i;
      position += steps * i;
      tag += steps;
    }
    for (; cur_q <= Q && query[cur_q].x <= position; cur_q++) {
      int fix = (position - query[cur_q].x) / i;
      query[cur_q].x += fix * i;
      query[cur_q].k -= fix;
      queue.push({query[cur_q].k + tag, get_kth(query[cur_q].x - position + i),
                  query[cur_q].id});
    }
    while (!queue.empty() && queue.top().times <= tag) {
      element e = queue.top();
      queue.pop();
      O[e.id] = position - i + G(1, 1, N, 1, e.ord) + (e.times - tag) * i;
    }
  }
  for (; cur_q <= Q; cur_q++)
    O[query[cur_q].id] = query[cur_q].x + (long long)query[cur_q].k * N;
  while (!queue.empty()) {
    element e = queue.top();
    queue.pop();
    O[e.id] = position - N + e.ord + (long long)(e.times - tag) * N;
  }
  for (int i = 1; i <= Q; i++) printf("%lld\n", O[i]);
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

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>
int a[100001], p[100001], N, Q, T[262144];
void build(int p, int l, int r, int w) {
  T[p] = (r - l + 1) * w;
  if (l < r) {
    int m = l + r >> 1;
    build(p << 1, l, m, w);
    build(p << 1 | 1, m + 1, r, w);
  }
}
int get_kth(int k) {
  int p = 1, l = 1, r = N;
  while (l < r) {
    int m = l + r >> 1;
    if (k <= T[p << 1])
      p <<= 1, r = m;
    else
      k -= T[p << 1], p = p << 1 | 1, l = m + 1;
  }
  return l;
}
void P(int x, int w) {
  int p = 1, l = 1, r = N;
  T[p] += w;
  while (l < r) {
    int m = l + r >> 1;
    if (x <= m)
      p <<= 1, r = m;
    else
      p = p << 1 | 1, l = m + 1;
    T[p] += w;
  }
}
struct query_t {
  int x, k, id;
} query[100001];
long long O[100001];
int position, tag;
struct element {
  int times, ord, id;
  inline bool operator<(const element &a) const { return times > a.times; }
};
std::priority_queue<element> queue;
int G(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return T[p];
  int m = l + r >> 1;
  if (R <= m) return G(p << 1, l, m, L, R);
  if (L > m) return G(p << 1 | 1, m + 1, r, L, R);
  return G(p << 1, l, m, L, R) + G(p << 1 | 1, m + 1, r, L, R);
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= N; i++) scanf("%d", a + i);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &query[i].x, &query[i].k);
    query[i].id = i;
  }
  for (int i = 2; i <= N; i++) p[i] = (p[i - 1] + a[i] - a[i - 1]) % (i - 1);
  build(1, 1, N, 1);
  for (int i = N; i; i--) {
    p[i] = get_kth(p[i] + 1);
    P(p[i], -1);
  }
  std::sort(query + 1, query + Q + 1,
            [](const query_t &a, const query_t &b) { return a.x < b.x; });
  int cur_q = 1;
  while (cur_q <= Q && query[cur_q].x < a[1]) {
    O[query[cur_q].id] = query[cur_q].x;
    cur_q++;
  }
  build(1, 1, N, 0);
  for (int i = 1; i < N; i++) {
    P(p[i], 1);
    if (i == 1)
      position = a[2] - 1;
    else {
      int steps = (a[i + 1] - 1 - position) / i;
      position += steps * i;
      tag += steps;
    }
    for (; cur_q <= Q && query[cur_q].x <= position; cur_q++) {
      int fix = (position - query[cur_q].x) / i;
      query[cur_q].x += fix * i;
      query[cur_q].k -= fix;
      queue.push({query[cur_q].k + tag, get_kth(query[cur_q].x - position + i),
                  query[cur_q].id});
    }
    while (!queue.empty() && queue.top().times <= tag) {
      element e = queue.top();
      queue.pop();
      O[e.id] = position - i + G(1, 1, N, 1, e.ord) + (e.times - tag) * i;
    }
  }
  for (; cur_q <= Q; cur_q++)
    O[query[cur_q].id] = query[cur_q].x + (long long)query[cur_q].k * N;
  while (!queue.empty()) {
    element e = queue.top();
    queue.pop();
    O[e.id] = position - N + e.ord + (long long)(e.times - tag) * N;
  }
  for (int i = 1; i <= Q; i++) printf("%lld\n", O[i]);
  return 0;
}

```