#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline long long squ(T x) {
  return (long long)x * x;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  T sum = 0, fg = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fg = -1;
  for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
  return fg * sum;
}
const int N = 1e6, inf = 0x3f3f3f3f;
const int maxn = 5e5 + 10;
const int maxm = 1e6 + 10;
int n, m, cnt[maxm], a[maxn];
namespace SEG {
const int maxn = ::maxm;
struct info {
  int v, mn;
  bool ok;
  info() {}
  info(int _v, int _mn, bool _ok) : v(_v), mn(_mn), ok(_ok) {}
  inline info operator+(const info &rhs) const {
    if (!rhs.ok) return *this;
    if (!this->ok) return rhs;
    if (mn < rhs.mn) return *this;
    if (mn > rhs.mn) return rhs;
    return info(v + rhs.v, mn, 1);
  }
};
struct node {
  info v;
  int tag;
  inline void operator+=(int t) { tag += t, v.mn += t; }
} A[maxn << 2];
inline void push_up(int rt) { A[rt].v = A[(rt << 1)].v + A[(rt << 1 | 1)].v; }
inline void push_down(int rt) {
  if (A[rt].tag)
    A[(rt << 1)] += A[rt].tag, A[(rt << 1 | 1)] += A[rt].tag, A[rt].tag = 0;
}
inline void build(int rt, int l, int r) {
  if (l == r) return void(A[rt].v = info(1, 0, cnt[l] ? 1 : 0));
  int mid = (l + r) >> 1;
  build((rt << 1), l, mid), build((rt << 1 | 1), mid + 1, r);
  push_up(rt);
}
inline void change(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return void(A[rt] += v);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) change((rt << 1), l, mid, L, R, v);
  if (R > mid) change((rt << 1 | 1), mid + 1, r, L, R, v);
  push_up(rt);
}
inline void Change(int l, int r, int v) {
  if (l <= r) change(1, 1, N, l, r, v);
}
inline void ins(int rt, int l, int r, int x) {
  if (l == r) return void(A[rt].v.ok = 1);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (x <= mid)
    ins((rt << 1), l, mid, x);
  else
    ins((rt << 1 | 1), mid + 1, r, x);
  push_up(rt);
}
inline void del(int rt, int l, int r, int x) {
  if (l == r) return void(A[rt].v.ok = 0);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (x <= mid)
    del((rt << 1), l, mid, x);
  else
    del((rt << 1 | 1), mid + 1, r, x);
  push_up(rt);
}
inline int query() { return A[1].v.v; }
}  // namespace SEG
int main() {
  n = read<int>(), m = read<int>();
  for (int i = 1; i <= n; i++) ++cnt[a[i] = read<int>()];
  SEG::build(1, 1, N);
  a[0] = N, a[n + 1] = 0;
  for (int i = 0; i <= n; i++) {
    int l = min(a[i + 1], a[i]), r = max(a[i + 1], a[i]);
    SEG::Change(l + 1, r, 1);
  }
  while (m--) {
    int x = read<int>(), y = read<int>();
    --cnt[a[x]];
    if (!cnt[a[x]]) SEG::del(1, 1, N, a[x]);
    if (!cnt[y]) SEG::ins(1, 1, N, y);
    ++cnt[y];
    if (y < a[x]) {
      SEG::Change(max(a[x - 1], y) + 1, a[x], -1);
      SEG::Change(max(a[x + 1], y) + 1, a[x], -1);
      SEG::Change(y + 1, min(a[x - 1], a[x]), 1);
      SEG::Change(y + 1, min(a[x + 1], a[x]), 1);
    } else {
      SEG::Change(a[x] + 1, min(a[x - 1], y), -1);
      SEG::Change(a[x] + 1, min(a[x + 1], y), -1);
      SEG::Change(max(a[x - 1], a[x]) + 1, y, 1);
      SEG::Change(max(a[x + 1], a[x]) + 1, y, 1);
    }
    printf("%d\n", SEG::query());
    a[x] = y;
  }
  return 0;
}

### Prompt

Please create a solution in CPP 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;
template <typename T>
inline long long squ(T x) {
  return (long long)x * x;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  T sum = 0, fg = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fg = -1;
  for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
  return fg * sum;
}
const int N = 1e6, inf = 0x3f3f3f3f;
const int maxn = 5e5 + 10;
const int maxm = 1e6 + 10;
int n, m, cnt[maxm], a[maxn];
namespace SEG {
const int maxn = ::maxm;
struct info {
  int v, mn;
  bool ok;
  info() {}
  info(int _v, int _mn, bool _ok) : v(_v), mn(_mn), ok(_ok) {}
  inline info operator+(const info &rhs) const {
    if (!rhs.ok) return *this;
    if (!this->ok) return rhs;
    if (mn < rhs.mn) return *this;
    if (mn > rhs.mn) return rhs;
    return info(v + rhs.v, mn, 1);
  }
};
struct node {
  info v;
  int tag;
  inline void operator+=(int t) { tag += t, v.mn += t; }
} A[maxn << 2];
inline void push_up(int rt) { A[rt].v = A[(rt << 1)].v + A[(rt << 1 | 1)].v; }
inline void push_down(int rt) {
  if (A[rt].tag)
    A[(rt << 1)] += A[rt].tag, A[(rt << 1 | 1)] += A[rt].tag, A[rt].tag = 0;
}
inline void build(int rt, int l, int r) {
  if (l == r) return void(A[rt].v = info(1, 0, cnt[l] ? 1 : 0));
  int mid = (l + r) >> 1;
  build((rt << 1), l, mid), build((rt << 1 | 1), mid + 1, r);
  push_up(rt);
}
inline void change(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return void(A[rt] += v);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) change((rt << 1), l, mid, L, R, v);
  if (R > mid) change((rt << 1 | 1), mid + 1, r, L, R, v);
  push_up(rt);
}
inline void Change(int l, int r, int v) {
  if (l <= r) change(1, 1, N, l, r, v);
}
inline void ins(int rt, int l, int r, int x) {
  if (l == r) return void(A[rt].v.ok = 1);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (x <= mid)
    ins((rt << 1), l, mid, x);
  else
    ins((rt << 1 | 1), mid + 1, r, x);
  push_up(rt);
}
inline void del(int rt, int l, int r, int x) {
  if (l == r) return void(A[rt].v.ok = 0);
  push_down(rt);
  int mid = (l + r) >> 1;
  if (x <= mid)
    del((rt << 1), l, mid, x);
  else
    del((rt << 1 | 1), mid + 1, r, x);
  push_up(rt);
}
inline int query() { return A[1].v.v; }
}  // namespace SEG
int main() {
  n = read<int>(), m = read<int>();
  for (int i = 1; i <= n; i++) ++cnt[a[i] = read<int>()];
  SEG::build(1, 1, N);
  a[0] = N, a[n + 1] = 0;
  for (int i = 0; i <= n; i++) {
    int l = min(a[i + 1], a[i]), r = max(a[i + 1], a[i]);
    SEG::Change(l + 1, r, 1);
  }
  while (m--) {
    int x = read<int>(), y = read<int>();
    --cnt[a[x]];
    if (!cnt[a[x]]) SEG::del(1, 1, N, a[x]);
    if (!cnt[y]) SEG::ins(1, 1, N, y);
    ++cnt[y];
    if (y < a[x]) {
      SEG::Change(max(a[x - 1], y) + 1, a[x], -1);
      SEG::Change(max(a[x + 1], y) + 1, a[x], -1);
      SEG::Change(y + 1, min(a[x - 1], a[x]), 1);
      SEG::Change(y + 1, min(a[x + 1], a[x]), 1);
    } else {
      SEG::Change(a[x] + 1, min(a[x - 1], y), -1);
      SEG::Change(a[x] + 1, min(a[x + 1], y), -1);
      SEG::Change(max(a[x - 1], a[x]) + 1, y, 1);
      SEG::Change(max(a[x + 1], a[x]) + 1, y, 1);
    }
    printf("%d\n", SEG::query());
    a[x] = y;
  }
  return 0;
}

```