# Zip-line

Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn’t remember exactly the heights of all trees in the forest. He is sure that he remembers correct heights of all trees except, possibly, one of them.

It is known that the forest consists of n trees staying in a row numbered from left to right with integers from 1 to n. According to Vasya, the height of the i-th tree is equal to h i. The zip-line of length k should hang over k (1 ≤ k ≤ n) trees i 1, i 2, …, i k ( i 1 < i 2 < … < i k) such that their heights form an increasing sequence, that is h i 1 < h i 2 < … < h i k.

Petya had been in this forest together with Vasya, and he now has q assumptions about the mistake in Vasya’s sequence h. His i-th assumption consists of two integers a i and b i indicating that, according to Petya, the height of the tree numbered a i is actually equal to b i. Note that Petya’s assumptions are independent from each other.

Your task is to find the maximum length of a zip-line that can be built over the trees under each of the q assumptions.

In this problem the length of a zip line is considered equal to the number of trees that form this zip-line.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 400 000) — the number of the trees in the forest and the number of Petya’s assumptions, respectively.

The following line contains n integers h i (1 ≤ h i ≤ 109) — the heights of trees according to Vasya.

Each of the following m lines contains two integers a i and b i (1 ≤ a i ≤ n, 1 ≤ b i ≤ 109).

Output

For each of the Petya’s assumptions output one integer, indicating the maximum length of a zip-line that can be built under this assumption.

Examples

input

4 41 2 3 41 11 44 34 5

output

4334

input

4 21 3 2 63 52 4

output

43

Note

Consider the first sample. The first assumption actually coincides with the height remembered by Vasya. In the second assumption the heights of the trees are (4, 2, 3, 4), in the third one they are (1, 2, 3, 3) and in the fourth one they are (1, 2, 3, 5).

Solution:

#include <bits/stdc++.h>

using namespace std;

const int N = 1200010;

int t, mx[N];

inline void modify(int x, int v) {
while (x <= t) {
if (v > mx[x]) {
mx[x] = v;
}
x = (x | (x - 1)) + 1;
}
}

inline int find_max(int x) {
int v = 0;
while (x > 0) {
if (mx[x] > v) {
v = mx[x];
}
x &= x - 1;
}
return v;
}

pair <int, int> ev[N];
int pos[N], value[N], with[N];
int dpleft[N], dpright[N];
vector <int> qs[N];
vector <int> who[N];
int h[N];
bool all[N];

int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", h + i);
ev[i] = make_pair(h[i], i);
}
for (int i = 0; i < m; i++) {
scanf("%d %d", pos + i, value + i);
pos[i]--;
ev[n + i] = make_pair(value[i], ~i);
with[i] = 1;
}
sort(ev, ev + n + m);
t = 0;
for (int i = 0; i < n + m; i++) {
if (i == 0 || ev[i].first != ev[i - 1].first) {
t++;
}
int id = ev[i].second;
if (id >= 0) {
h[id] = t;
} else {
value[~id] = t;
}
}
for (int i = 0; i < n; i++) {
qs[i].clear();
}
for (int i = 0; i < m; i++) {
qs[pos[i]].push_back(i);
}
for (int i = 1; i <= t; i++) {
mx[i] = 0;
}
for (int i = 0; i < n; i++) {
dpleft[i] = find_max(h[i] - 1) + 1;
int sz = qs[i].size();
for (int j = 0; j < sz; j++) {
int qid = qs[i][j];
with[qid] += find_max(value[qid] - 1);
}
modify(h[i], dpleft[i]);
}
for (int i = 1; i <= t; i++) {
mx[i] = 0;
}
for (int i = n - 1; i >= 0; i--) {
dpright[i] = find_max(t - h[i]) + 1;
int sz = qs[i].size();
for (int j = 0; j < sz; j++) {
int qid = qs[i][j];
with[qid] += find_max(t - value[qid]);
}
modify(t - h[i] + 1, dpright[i]);
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, dpleft[i]);
}
for (int i = 1; i <= ans; i++) {
who[i].clear();
}
for (int i = 0; i < n; i++) {
int total = dpleft[i] + dpright[i] - 1;
if (total != ans) {
continue;
}
who[dpleft[i]].push_back(i);
}
for (int i = 0; i < n; i++) {
all[i] = false;
}
for (int i = 1; i <= ans; i++) {
int sz = who[i].size();
if (sz != 1) {
continue;
}
all[who[i]] = true;
}
for (int i = 0; i < m; i++) {
int res = with[i];
if (all[pos[i]]) {
res = max(res, ans - 1);
} else {
res = max(res, ans);
}
printf("%d\n", res);
}
return 0;
}