#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
namespace input {
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
void re(long double& x) {
  string t;
  re(t);
  x = stold(t);
}
template <class T, class... Ts>
void re(T& t, Ts&... ts) {
  re(t);
  re(ts...);
}
template <class T>
void re(complex<T>& x) {
  T a, b;
  re(a, b);
  x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = (0); i < ((int)a.size()); ++i) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = (0); i < (SZ); ++i) re(a[i]);
}
}  // namespace input
using namespace input;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(long long x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T>
void pr(const complex<T>& x) {
  cout << x;
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
  pr(t);
  pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void pr(const T& x) {
  pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(" ");
  ps(ts...);
}
void pc() { pr("]\n"); }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(", ");
  pc(ts...);
}
}  // namespace output
using namespace output;
namespace io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  cin.sync_with_stdio(0);
  cin.tie(0);
  if ((int)second.size()) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace io
using namespace io;
typedef decay<decltype(MOD)>::type T;
struct mi {
  T val;
  explicit operator T() const { return val; }
  mi() { val = 0; }
  mi(const long long& v) {
    val = (-MOD <= v && v <= MOD) ? v : v % MOD;
    if (val < 0) val += MOD;
  }
  friend void pr(const mi& a) { pr(a.val); }
  friend void re(mi& a) {
    long long x;
    re(x);
    a = mi(x);
  }
  friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
  friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
  friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
  mi operator-() const { return mi(-val); }
  mi& operator+=(const mi& m) {
    if ((val += m.val) >= MOD) val -= MOD;
    return *this;
  }
  mi& operator-=(const mi& m) {
    if ((val -= m.val) < 0) val += MOD;
    return *this;
  }
  mi& operator*=(const mi& m) {
    val = (long long)val * m.val % MOD;
    return *this;
  }
  friend mi pow(mi a, long long p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1) ans *= a;
    return ans;
  }
  friend mi inv(const mi& a) {
    assert(a != 0);
    return pow(a, MOD - 2);
  }
  mi& operator/=(const mi& m) { return (*this) *= inv(m); }
  friend mi operator+(mi a, const mi& b) { return a += b; }
  friend mi operator-(mi a, const mi& b) { return a -= b; }
  friend mi operator*(mi a, const mi& b) { return a *= b; }
  friend mi operator/(mi a, const mi& b) { return a /= b; }
};
long long cdiv(long long a, long long b) { return (a + b - 1) / b; }
vector<long long> a;
int n, m;
vector<array<long long, 3>> seg[1 << 18];
void build(int ind = 1, int l = 1, int r = n) {
  if (l == r) {
    seg[ind].push_back({0, cdiv(a[l] - a[l - 1], l)});
    seg[ind][0][2] = seg[ind][0][1] * l;
    if ((a[l] - a[l - 1]) % l) {
      seg[ind].push_back({(a[l] - a[l - 1]) % l, (a[l] - a[l - 1]) / l});
      seg[ind][1][2] = seg[ind][1][1] * l;
    }
    seg[ind].push_back({l});
    return;
  }
  int m = (l + r) / 2;
  build(2 * ind, l, m), build(2 * ind + 1, m + 1, r);
  for (int i = (0); i < ((int)seg[2 * ind].size() - 1); ++i) {
    long long L = a[l - 1] + seg[2 * ind][i][0] + seg[2 * ind][i][2];
    long long R = a[l - 1] + seg[2 * ind][i + 1][0] + seg[2 * ind][i][2];
    int k = lower_bound(begin(seg[2 * ind + 1]), end(seg[2 * ind + 1]),
                        array<long long, 3>{L - a[m] + 1}) -
            begin(seg[2 * ind + 1]) - 1;
    for (; a[m] + seg[2 * ind + 1][k][0] < R; ++k) {
      seg[ind].push_back(
          {seg[2 * ind][i][0] + max(a[m] + seg[2 * ind + 1][k][0] - L, 0LL),
           seg[2 * ind][i][1] + seg[2 * ind + 1][k][1],
           seg[2 * ind][i][2] + seg[2 * ind + 1][k][2]});
    }
  }
  seg[ind].push_back({l});
}
void query(int pos, long long& x, long long& k, int ind = 1, int l = 1,
           int r = n) {
  if (!k || r < pos) return;
  if (l >= pos) {
    auto des = *(lower_bound(begin(seg[ind]), end(seg[ind]),
                             array<long long, 3>{x - a[l - 1] + 1}) -
                 1);
    if (des[1] <= k) {
      x += des[2];
      k -= des[1];
      return;
    }
  }
  if (l == r) {
    x += k * l;
    k = 0;
    return;
  }
  int m = (l + r) / 2;
  query(pos, x, k, 2 * ind, l, m);
  query(pos, x, k, 2 * ind + 1, m + 1, r);
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  re(n, m);
  a.resize(n);
  re(a);
  for (int i = (0); i < (n); ++i) a[i] -= i;
  a.push_back(1e15);
  build(1, 1, n);
  for (int i = (0); i < (m); ++i) {
    long long x, k;
    re(x, k);
    int pos = upper_bound(begin(a), end(a), x) - begin(a);
    if (pos) {
      k += (x - a[pos - 1]) / pos;
      x -= (x - a[pos - 1]) / pos * pos;
      query(pos, x, k);
    }
    ps(x);
  }
}

### Prompt

In cpp, your task is to solve 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 int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
namespace input {
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
void re(long double& x) {
  string t;
  re(t);
  x = stold(t);
}
template <class T, class... Ts>
void re(T& t, Ts&... ts) {
  re(t);
  re(ts...);
}
template <class T>
void re(complex<T>& x) {
  T a, b;
  re(a, b);
  x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = (0); i < ((int)a.size()); ++i) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = (0); i < (SZ); ++i) re(a[i]);
}
}  // namespace input
using namespace input;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(long long x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T>
void pr(const complex<T>& x) {
  cout << x;
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
  pr(t);
  pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void pr(const T& x) {
  pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(" ");
  ps(ts...);
}
void pc() { pr("]\n"); }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(", ");
  pc(ts...);
}
}  // namespace output
using namespace output;
namespace io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  cin.sync_with_stdio(0);
  cin.tie(0);
  if ((int)second.size()) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace io
using namespace io;
typedef decay<decltype(MOD)>::type T;
struct mi {
  T val;
  explicit operator T() const { return val; }
  mi() { val = 0; }
  mi(const long long& v) {
    val = (-MOD <= v && v <= MOD) ? v : v % MOD;
    if (val < 0) val += MOD;
  }
  friend void pr(const mi& a) { pr(a.val); }
  friend void re(mi& a) {
    long long x;
    re(x);
    a = mi(x);
  }
  friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
  friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
  friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
  mi operator-() const { return mi(-val); }
  mi& operator+=(const mi& m) {
    if ((val += m.val) >= MOD) val -= MOD;
    return *this;
  }
  mi& operator-=(const mi& m) {
    if ((val -= m.val) < 0) val += MOD;
    return *this;
  }
  mi& operator*=(const mi& m) {
    val = (long long)val * m.val % MOD;
    return *this;
  }
  friend mi pow(mi a, long long p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1) ans *= a;
    return ans;
  }
  friend mi inv(const mi& a) {
    assert(a != 0);
    return pow(a, MOD - 2);
  }
  mi& operator/=(const mi& m) { return (*this) *= inv(m); }
  friend mi operator+(mi a, const mi& b) { return a += b; }
  friend mi operator-(mi a, const mi& b) { return a -= b; }
  friend mi operator*(mi a, const mi& b) { return a *= b; }
  friend mi operator/(mi a, const mi& b) { return a /= b; }
};
long long cdiv(long long a, long long b) { return (a + b - 1) / b; }
vector<long long> a;
int n, m;
vector<array<long long, 3>> seg[1 << 18];
void build(int ind = 1, int l = 1, int r = n) {
  if (l == r) {
    seg[ind].push_back({0, cdiv(a[l] - a[l - 1], l)});
    seg[ind][0][2] = seg[ind][0][1] * l;
    if ((a[l] - a[l - 1]) % l) {
      seg[ind].push_back({(a[l] - a[l - 1]) % l, (a[l] - a[l - 1]) / l});
      seg[ind][1][2] = seg[ind][1][1] * l;
    }
    seg[ind].push_back({l});
    return;
  }
  int m = (l + r) / 2;
  build(2 * ind, l, m), build(2 * ind + 1, m + 1, r);
  for (int i = (0); i < ((int)seg[2 * ind].size() - 1); ++i) {
    long long L = a[l - 1] + seg[2 * ind][i][0] + seg[2 * ind][i][2];
    long long R = a[l - 1] + seg[2 * ind][i + 1][0] + seg[2 * ind][i][2];
    int k = lower_bound(begin(seg[2 * ind + 1]), end(seg[2 * ind + 1]),
                        array<long long, 3>{L - a[m] + 1}) -
            begin(seg[2 * ind + 1]) - 1;
    for (; a[m] + seg[2 * ind + 1][k][0] < R; ++k) {
      seg[ind].push_back(
          {seg[2 * ind][i][0] + max(a[m] + seg[2 * ind + 1][k][0] - L, 0LL),
           seg[2 * ind][i][1] + seg[2 * ind + 1][k][1],
           seg[2 * ind][i][2] + seg[2 * ind + 1][k][2]});
    }
  }
  seg[ind].push_back({l});
}
void query(int pos, long long& x, long long& k, int ind = 1, int l = 1,
           int r = n) {
  if (!k || r < pos) return;
  if (l >= pos) {
    auto des = *(lower_bound(begin(seg[ind]), end(seg[ind]),
                             array<long long, 3>{x - a[l - 1] + 1}) -
                 1);
    if (des[1] <= k) {
      x += des[2];
      k -= des[1];
      return;
    }
  }
  if (l == r) {
    x += k * l;
    k = 0;
    return;
  }
  int m = (l + r) / 2;
  query(pos, x, k, 2 * ind, l, m);
  query(pos, x, k, 2 * ind + 1, m + 1, r);
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  re(n, m);
  a.resize(n);
  re(a);
  for (int i = (0); i < (n); ++i) a[i] -= i;
  a.push_back(1e15);
  build(1, 1, n);
  for (int i = (0); i < (m); ++i) {
    long long x, k;
    re(x, k);
    int pos = upper_bound(begin(a), end(a), x) - begin(a);
    if (pos) {
      k += (x - a[pos - 1]) / pos;
      x -= (x - a[pos - 1]) / pos * pos;
      query(pos, x, k);
    }
    ps(x);
  }
}

```