#include <bits/stdc++.h>
using namespace std;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
const int maxn = 500111;
const int mod = 1e9 + 7;
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
struct node {
  int mn, mx;
  node *tl, *tr;
  int ans, l_ask_r, r_ask_l;
  void init(int v) {
    mn = mx = v;
    tl = tr = NULL;
    ans = 1;
    l_ask_r = r_ask_l = 0;
  }
  void compute() {
    mn = min(tl->mn, tr->mn);
    mx = max(tl->mx, tr->mx);
    l_ask_r = tr->query(tl->mn, -1);
    r_ask_l = tl->query(1e7, tr->mx);
  }
  int get_ans() { return query(1e7, -1) + 1; }
  void debug() {
    if (tl) tl->debug();
    if (tr) tr->debug();
    if (0)
      cout << mn << " " << mx << "  " << l_ask_r << "," << r_ask_l << " " << ans
           << endl;
  }
  int query(int x, int y) {
    if (tl == NULL) return 0;
    if (x <= y) return 0;
    if (x <= mn || mx <= y) return 0;
    int ret = (min(x, tl->mn) > max(y, tr->mx));
    if (x >= tl->mx && max(y, tr->mx) == tr->mx)
      ret += r_ask_l;
    else
      ret += tl->query(x, max(y, tr->mx));
    if (y <= tr->mn && min(x, tl->mn) == tl->mn)
      ret += l_ask_r;
    else
      ret += tr->query(min(x, tl->mn), y);
    return ret;
  }
};
int n, q;
int a[maxn];
node *build_single(int v) {
  node *ret = new node;
  ret->init(v);
  return ret;
}
node *build(int l, int r) {
  if (l == r) return build_single(a[l]);
  node *ret = new node;
  int m = l + r >> 1;
  ret->tl = build(l, m);
  ret->tr = build(m + 1, r);
  ret->compute();
  return ret;
}
void modify(int x, int v, node *p, int l, int r) {
  if (l == r) {
    p->init(v);
    return;
  }
  int m = l + r >> 1;
  if (x <= m)
    modify(x, v, p->tl, l, m);
  else
    modify(x, v, p->tr, m + 1, r);
  p->compute();
}
int main() {
  n = getnum(), q = getnum();
  for (int i = 1; i <= n; i++) {
    a[i] = getnum();
  }
  node *rt = build(1, n);
  for (int i = 1; i <= q; i++) {
    int x, v;
    x = getnum(), v = getnum();
    modify(x, v, rt, 1, n);
    putnum(rt->get_ans()), putchar('\n');
  }
  return 0;
}

### Prompt

Please formulate 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;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
const int maxn = 500111;
const int mod = 1e9 + 7;
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
struct node {
  int mn, mx;
  node *tl, *tr;
  int ans, l_ask_r, r_ask_l;
  void init(int v) {
    mn = mx = v;
    tl = tr = NULL;
    ans = 1;
    l_ask_r = r_ask_l = 0;
  }
  void compute() {
    mn = min(tl->mn, tr->mn);
    mx = max(tl->mx, tr->mx);
    l_ask_r = tr->query(tl->mn, -1);
    r_ask_l = tl->query(1e7, tr->mx);
  }
  int get_ans() { return query(1e7, -1) + 1; }
  void debug() {
    if (tl) tl->debug();
    if (tr) tr->debug();
    if (0)
      cout << mn << " " << mx << "  " << l_ask_r << "," << r_ask_l << " " << ans
           << endl;
  }
  int query(int x, int y) {
    if (tl == NULL) return 0;
    if (x <= y) return 0;
    if (x <= mn || mx <= y) return 0;
    int ret = (min(x, tl->mn) > max(y, tr->mx));
    if (x >= tl->mx && max(y, tr->mx) == tr->mx)
      ret += r_ask_l;
    else
      ret += tl->query(x, max(y, tr->mx));
    if (y <= tr->mn && min(x, tl->mn) == tl->mn)
      ret += l_ask_r;
    else
      ret += tr->query(min(x, tl->mn), y);
    return ret;
  }
};
int n, q;
int a[maxn];
node *build_single(int v) {
  node *ret = new node;
  ret->init(v);
  return ret;
}
node *build(int l, int r) {
  if (l == r) return build_single(a[l]);
  node *ret = new node;
  int m = l + r >> 1;
  ret->tl = build(l, m);
  ret->tr = build(m + 1, r);
  ret->compute();
  return ret;
}
void modify(int x, int v, node *p, int l, int r) {
  if (l == r) {
    p->init(v);
    return;
  }
  int m = l + r >> 1;
  if (x <= m)
    modify(x, v, p->tl, l, m);
  else
    modify(x, v, p->tr, m + 1, r);
  p->compute();
}
int main() {
  n = getnum(), q = getnum();
  for (int i = 1; i <= n; i++) {
    a[i] = getnum();
  }
  node *rt = build(1, n);
  for (int i = 1; i <= q; i++) {
    int x, v;
    x = getnum(), v = getnum();
    modify(x, v, rt, 1, n);
    putnum(rt->get_ans()), putchar('\n');
  }
  return 0;
}

```