#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, maxa = 1e6 + 5;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
int n, q, a[maxn], A;
pair<int, int> sum[maxa << 2];
int tag[maxa << 2];
pair<int, int> operator+(pair<int, int> a, int b) {
  a.first += b;
  return a;
}
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  if (a > b) swap(a, b);
  if (a.first == b.first) a.second += b.second;
  return a;
}
void modify1(int s, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return sum[s].first += v, tag[s] += v, void();
  if (ql <= ((l + r) >> 1)) modify1((s << 1), l, ((l + r) >> 1), ql, qr, v);
  if (qr >= ((l + r) >> 1) + 1)
    modify1((s << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v);
  sum[s] = sum[(s << 1)] + sum[(s << 1 | 1)] + tag[s];
}
void modify2(int s, int l, int r, int p, int v) {
  if (l == r) return sum[s].second += v, void();
  if (p <= ((l + r) >> 1))
    modify2((s << 1), l, ((l + r) >> 1), p, v);
  else
    modify2((s << 1 | 1), ((l + r) >> 1) + 1, r, p, v);
  sum[s] = sum[(s << 1)] + sum[(s << 1 | 1)] + tag[s];
}
int query(int s, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return sum[s].first + v == 1 ? sum[s].second : 0;
  int res = 0;
  if (ql <= ((l + r) >> 1))
    res += query((s << 1), l, ((l + r) >> 1), ql, qr, v + tag[s]);
  if (qr >= ((l + r) >> 1) + 1)
    res += query((s << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v + tag[s]);
  return res;
}
void mdf(int l, int r, int v) {
  if (l != r) modify1(1, 0, A, min(l, r), max(l, r) - 1, v);
}
int main() {
  n = gi();
  q = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi();
  a[0] = A = 1e6 + 1;
  for (int i = 0; i <= n; ++i)
    mdf(a[i], a[i + 1], 1), modify2(1, 0, A, a[i], 1);
  int x, v;
  while (q--) {
    x = gi();
    v = gi();
    mdf(a[x - 1], a[x], -1);
    mdf(a[x], a[x + 1], -1);
    modify2(1, 0, A, a[x], -1);
    a[x] = v;
    mdf(a[x - 1], a[x], 1);
    mdf(a[x], a[x + 1], 1);
    modify2(1, 0, A, a[x], 1);
    printf("%d\n", query(1, 0, A, 1, A - 1, 0));
  }
  return 0;
}

### Prompt

Your task is to create a Cpp solution to the following problem:

Suppose that we have an array of n distinct numbers a_1, a_2, ..., a_n. Let's build a graph on n vertices as follows: for every pair of vertices i < j let's connect i and j with an edge, if a_i < a_j. Let's define weight of the array to be the number of connected components in this graph. For example, weight of array [1, 4, 2] is 1, weight of array [5, 4, 3] is 3.

You have to perform q queries of the following form — change the value at some position of the array. After each operation, output the weight of the array. Updates are not independent (the change stays for the future).

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 5 ⋅ 10^5) — the size of the array and the number of queries.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6) — the initial array.

Each of the next q lines contains two integers pos and x (1 ≤ pos ≤ n, 1 ≤ x ≤ 10^6, x ≠ a_{pos}). It means that you have to make a_{pos}=x.

It's guaranteed that at every moment of time, all elements of the array are different.

Output

After each query, output the weight of the array.

Example

Input


5 3
50 40 30 20 10
1 25
3 45
1 48


Output


3
3
4

Note

After the first query array looks like [25, 40, 30, 20, 10], the weight is equal to 3.

After the second query array looks like [25, 40, 45, 20, 10], the weight is still equal to 3.

After the third query array looks like [48, 40, 45, 20, 10], the weight is equal to 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, maxa = 1e6 + 5;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
int n, q, a[maxn], A;
pair<int, int> sum[maxa << 2];
int tag[maxa << 2];
pair<int, int> operator+(pair<int, int> a, int b) {
  a.first += b;
  return a;
}
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  if (a > b) swap(a, b);
  if (a.first == b.first) a.second += b.second;
  return a;
}
void modify1(int s, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return sum[s].first += v, tag[s] += v, void();
  if (ql <= ((l + r) >> 1)) modify1((s << 1), l, ((l + r) >> 1), ql, qr, v);
  if (qr >= ((l + r) >> 1) + 1)
    modify1((s << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v);
  sum[s] = sum[(s << 1)] + sum[(s << 1 | 1)] + tag[s];
}
void modify2(int s, int l, int r, int p, int v) {
  if (l == r) return sum[s].second += v, void();
  if (p <= ((l + r) >> 1))
    modify2((s << 1), l, ((l + r) >> 1), p, v);
  else
    modify2((s << 1 | 1), ((l + r) >> 1) + 1, r, p, v);
  sum[s] = sum[(s << 1)] + sum[(s << 1 | 1)] + tag[s];
}
int query(int s, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) return sum[s].first + v == 1 ? sum[s].second : 0;
  int res = 0;
  if (ql <= ((l + r) >> 1))
    res += query((s << 1), l, ((l + r) >> 1), ql, qr, v + tag[s]);
  if (qr >= ((l + r) >> 1) + 1)
    res += query((s << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v + tag[s]);
  return res;
}
void mdf(int l, int r, int v) {
  if (l != r) modify1(1, 0, A, min(l, r), max(l, r) - 1, v);
}
int main() {
  n = gi();
  q = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi();
  a[0] = A = 1e6 + 1;
  for (int i = 0; i <= n; ++i)
    mdf(a[i], a[i + 1], 1), modify2(1, 0, A, a[i], 1);
  int x, v;
  while (q--) {
    x = gi();
    v = gi();
    mdf(a[x - 1], a[x], -1);
    mdf(a[x], a[x + 1], -1);
    modify2(1, 0, A, a[x], -1);
    a[x] = v;
    mdf(a[x - 1], a[x], 1);
    mdf(a[x], a[x + 1], 1);
    modify2(1, 0, A, a[x], 1);
    printf("%d\n", query(1, 0, A, 1, A - 1, 0));
  }
  return 0;
}

```