#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
namespace fastio {
char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;
inline char getc() {
  return p1 == p2 &&
                 (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline void putc(char x) { (*p3++ = x); }
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 0;
  while (!isdigit(c)) neg |= !(c ^ '-'), c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (neg) x = (~x) + 1;
}
template <typename T>
void recursive_print(T x) {
  if (!x) return;
  recursive_print(x / 10);
  putc(x % 10 ^ 48);
}
template <typename T>
void print(T x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = ~x + 1;
  recursive_print(x);
}
void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }
}  // namespace fastio
const int MAXN = 5e5;
const int MAXV = 1e6;
int n, qu, a[MAXN + 5];
struct node {
  int l, r, mn, mnc, lz;
} s[MAXV * 4 + 5];
void pushup(int k) {
  s[k].mn = min(s[k << 1].mn, s[k << 1 | 1].mn);
  s[k].mnc = 0;
  if (s[k].mn == s[k << 1].mn) s[k].mnc += s[k << 1].mnc;
  if (s[k].mn == s[k << 1 | 1].mn) s[k].mnc += s[k << 1 | 1].mnc;
}
void build(int k, int l, int r) {
  s[k].l = l;
  s[k].r = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void pushdown(int k) {
  if (s[k].lz) {
    s[k << 1].mn += s[k].lz;
    s[k << 1].lz += s[k].lz;
    s[k << 1 | 1].mn += s[k].lz;
    s[k << 1 | 1].lz += s[k].lz;
    s[k].lz = 0;
  }
}
void modify_mnc(int k, int p, int x) {
  if (s[k].l == s[k].r) {
    s[k].mnc += x;
    return;
  }
  pushdown(k);
  int mid = s[k].l + s[k].r >> 1;
  if (p <= mid)
    modify_mnc(k << 1, p, x);
  else
    modify_mnc(k << 1 | 1, p, x);
  pushup(k);
}
void modify(int k, int l, int r, int x) {
  if (l > r) return;
  if (l <= s[k].l && s[k].r <= r) {
    s[k].lz += x;
    s[k].mn += x;
    return;
  }
  pushdown(k);
  int mid = s[k].l + s[k].r >> 1;
  if (r <= mid)
    modify(k << 1, l, r, x);
  else if (l > mid)
    modify(k << 1 | 1, l, r, x);
  else
    modify(k << 1, l, mid, x), modify(k << 1 | 1, mid + 1, r, x);
  pushup(k);
}
void update(int x, int v) {
  modify(1, min(a[x], a[x + 1]), max(a[x], a[x + 1]) - 1, v);
}
int main() {
  scanf("%d%d", &n, &qu);
  multiset<int> st;
  a[0] = MAXV + 1;
  a[n + 1] = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), st.insert(a[i]);
  build(1, 0, MAXV);
  for (int i = 1; i <= n; i++) modify_mnc(1, a[i], 1);
  for (int i = 0; i <= n; i++) update(i, 1);
  while (qu--) {
    int x, v;
    scanf("%d%d", &x, &v);
    st.erase(st.find(a[x]));
    update(x - 1, -1);
    update(x, -1);
    modify_mnc(1, a[x], -1);
    a[x] = v;
    st.insert(v);
    update(x - 1, 1);
    update(x, 1);
    modify_mnc(1, a[x], 1);
    printf("%d\n", s[1].mnc);
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
namespace fastio {
char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;
inline char getc() {
  return p1 == p2 &&
                 (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline void putc(char x) { (*p3++ = x); }
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 0;
  while (!isdigit(c)) neg |= !(c ^ '-'), c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (neg) x = (~x) + 1;
}
template <typename T>
void recursive_print(T x) {
  if (!x) return;
  recursive_print(x / 10);
  putc(x % 10 ^ 48);
}
template <typename T>
void print(T x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = ~x + 1;
  recursive_print(x);
}
void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }
}  // namespace fastio
const int MAXN = 5e5;
const int MAXV = 1e6;
int n, qu, a[MAXN + 5];
struct node {
  int l, r, mn, mnc, lz;
} s[MAXV * 4 + 5];
void pushup(int k) {
  s[k].mn = min(s[k << 1].mn, s[k << 1 | 1].mn);
  s[k].mnc = 0;
  if (s[k].mn == s[k << 1].mn) s[k].mnc += s[k << 1].mnc;
  if (s[k].mn == s[k << 1 | 1].mn) s[k].mnc += s[k << 1 | 1].mnc;
}
void build(int k, int l, int r) {
  s[k].l = l;
  s[k].r = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void pushdown(int k) {
  if (s[k].lz) {
    s[k << 1].mn += s[k].lz;
    s[k << 1].lz += s[k].lz;
    s[k << 1 | 1].mn += s[k].lz;
    s[k << 1 | 1].lz += s[k].lz;
    s[k].lz = 0;
  }
}
void modify_mnc(int k, int p, int x) {
  if (s[k].l == s[k].r) {
    s[k].mnc += x;
    return;
  }
  pushdown(k);
  int mid = s[k].l + s[k].r >> 1;
  if (p <= mid)
    modify_mnc(k << 1, p, x);
  else
    modify_mnc(k << 1 | 1, p, x);
  pushup(k);
}
void modify(int k, int l, int r, int x) {
  if (l > r) return;
  if (l <= s[k].l && s[k].r <= r) {
    s[k].lz += x;
    s[k].mn += x;
    return;
  }
  pushdown(k);
  int mid = s[k].l + s[k].r >> 1;
  if (r <= mid)
    modify(k << 1, l, r, x);
  else if (l > mid)
    modify(k << 1 | 1, l, r, x);
  else
    modify(k << 1, l, mid, x), modify(k << 1 | 1, mid + 1, r, x);
  pushup(k);
}
void update(int x, int v) {
  modify(1, min(a[x], a[x + 1]), max(a[x], a[x + 1]) - 1, v);
}
int main() {
  scanf("%d%d", &n, &qu);
  multiset<int> st;
  a[0] = MAXV + 1;
  a[n + 1] = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), st.insert(a[i]);
  build(1, 0, MAXV);
  for (int i = 1; i <= n; i++) modify_mnc(1, a[i], 1);
  for (int i = 0; i <= n; i++) update(i, 1);
  while (qu--) {
    int x, v;
    scanf("%d%d", &x, &v);
    st.erase(st.find(a[x]));
    update(x - 1, -1);
    update(x, -1);
    modify_mnc(1, a[x], -1);
    a[x] = v;
    st.insert(v);
    update(x - 1, 1);
    update(x, 1);
    modify_mnc(1, a[x], 1);
    printf("%d\n", s[1].mnc);
  }
  return 0;
}

```