#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
struct SegTree {
  struct Node {
    long long x = 0;
    int cnt = 1;
    long long prop = 0;
    void apply(int s, int e, long long v) {
      x += v;
      prop += v;
    }
  };
  inline Node combine(const Node& a, const Node& b) {
    Node res;
    res.x = min(a.x, b.x);
    res.cnt = 0;
    if (res.x == a.x) res.cnt += a.cnt;
    if (res.x == b.x) res.cnt += b.cnt;
    return res;
  }
  inline void push(int sn, int s, int e) {
    if (tree[sn].prop) {
      int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
      tree[lsn].apply(s, m, tree[sn].prop);
      tree[rsn].apply(m + 1, e, tree[sn].prop);
      tree[sn].prop = 0;
    }
  }
  int start, end;
  vector<Node> tree;
  void build(int sn, int s, int e) {
    if (s == e) {
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    build(lsn, s, m);
    build(rsn, m + 1, e);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  template <typename T>
  void build(int sn, int s, int e, vector<T>& v) {
    if (s == e) {
      tree[sn].x = v[s];
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    build(lsn, s, m, v);
    build(rsn, m + 1, e, v);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  template <typename... T>
  void update(int sn, int s, int e, int qs, int qe, const T&... v) {
    if (qs <= s && e <= qe) {
      tree[sn].apply(s, e, v...);
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qs <= m) update(lsn, s, m, qs, qe, v...);
    if (qe > m) update(rsn, m + 1, e, qs, qe, v...);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  Node query(int sn, int s, int e, int qs, int qe) {
    if (qs <= s && e <= qe) return tree[sn];
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qe <= m) return query(lsn, s, m, qs, qe);
    if (qs > m) return query(rsn, m + 1, e, qs, qe);
    return combine(query(lsn, s, m, qs, qe), query(rsn, m + 1, e, qs, qe));
  }
  void query(int sn, int s, int e, int qs, int qe,
             const function<void(Node&, int, int)>& f) {
    if (qs <= s && e <= qe) return f(tree[sn], s, e);
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qs <= m) query(lsn, s, m, qs, qe, f);
    if (qe > m) query(rsn, m + 1, e, qs, qe, f);
  }
  SegTree(int n) : SegTree(0, n - 1) {}
  SegTree(int _start, int _end) : start(_start), end(_end) {
    int n = end - start + 1;
    int maxs = n == 1 ? 2 : 1 << (33 - __builtin_clz(n - 1));
    tree.resize(maxs);
    build(1, start, end);
  }
  template <typename T>
  SegTree(vector<T>& v) {
    int n = v.size();
    int maxs = n == 1 ? 2 : 1 << (33 - __builtin_clz(n - 1));
    tree.resize(maxs);
    start = 0;
    end = n - 1;
    build(1, start, end, v);
  }
  Node query(int qs, int qe) { return query(1, start, end, qs, qe); }
  Node query(int p) { return query(1, start, end, p, p); }
  void query(int qs, int qe, const function<void(Node&, int, int)>& f) {
    if (qs > qe) return;
    query(1, start, end, qs, qe, f);
  }
  template <typename... T>
  void update(int qs, int qe, const T&... v) {
    update(1, start, end, qs, qe, v...);
  }
};
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  const int MAX = 1000001;
  vector<int> A(n), pos(MAX);
  set<int> S = {-1, MAX + 1};
  SegTree st(n);
  auto handle = [&](int i, int j, int u) {
    if (i < 0 || j < 0 || i > MAX || j > MAX) return;
    if (pos[i] > pos[j]) return;
    st.update(pos[i], pos[j] - 1, u);
  };
  auto rem = [&](int x) {
    auto it = S.find(x);
    assert(it != S.end());
    auto pit = prev(it);
    handle(*pit, x, -1);
    auto nit = next(it);
    handle(x, *nit, -1);
    handle(*pit, *nit, 1);
    S.erase(it);
  };
  auto add = [&](int x) {
    auto it = S.lower_bound(x);
    auto pit = prev(it);
    handle(*pit, *it, -1);
    handle(*pit, x, 1);
    handle(x, *it, 1);
    S.insert(x);
  };
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    pos[A[i]] = i;
    add(A[i]);
  }
  while (q--) {
    int p, x;
    scanf("%d%d", &p, &x);
    --p;
    rem(A[p]);
    A[p] = x;
    pos[x] = p;
    add(A[p]);
    if (n == 1) {
      printf("1\n");
      continue;
    }
    auto v = st.query(0, n - 2);
    int ans = v.x == 0 ? 1 + v.cnt : 1;
    printf("%d\n", ans);
  }
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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 A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
struct SegTree {
  struct Node {
    long long x = 0;
    int cnt = 1;
    long long prop = 0;
    void apply(int s, int e, long long v) {
      x += v;
      prop += v;
    }
  };
  inline Node combine(const Node& a, const Node& b) {
    Node res;
    res.x = min(a.x, b.x);
    res.cnt = 0;
    if (res.x == a.x) res.cnt += a.cnt;
    if (res.x == b.x) res.cnt += b.cnt;
    return res;
  }
  inline void push(int sn, int s, int e) {
    if (tree[sn].prop) {
      int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
      tree[lsn].apply(s, m, tree[sn].prop);
      tree[rsn].apply(m + 1, e, tree[sn].prop);
      tree[sn].prop = 0;
    }
  }
  int start, end;
  vector<Node> tree;
  void build(int sn, int s, int e) {
    if (s == e) {
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    build(lsn, s, m);
    build(rsn, m + 1, e);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  template <typename T>
  void build(int sn, int s, int e, vector<T>& v) {
    if (s == e) {
      tree[sn].x = v[s];
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    build(lsn, s, m, v);
    build(rsn, m + 1, e, v);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  template <typename... T>
  void update(int sn, int s, int e, int qs, int qe, const T&... v) {
    if (qs <= s && e <= qe) {
      tree[sn].apply(s, e, v...);
      return;
    }
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qs <= m) update(lsn, s, m, qs, qe, v...);
    if (qe > m) update(rsn, m + 1, e, qs, qe, v...);
    tree[sn] = combine(tree[lsn], tree[rsn]);
  }
  Node query(int sn, int s, int e, int qs, int qe) {
    if (qs <= s && e <= qe) return tree[sn];
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qe <= m) return query(lsn, s, m, qs, qe);
    if (qs > m) return query(rsn, m + 1, e, qs, qe);
    return combine(query(lsn, s, m, qs, qe), query(rsn, m + 1, e, qs, qe));
  }
  void query(int sn, int s, int e, int qs, int qe,
             const function<void(Node&, int, int)>& f) {
    if (qs <= s && e <= qe) return f(tree[sn], s, e);
    int m = (s + e) >> 1, lsn = sn * 2, rsn = sn * 2 + 1;
    push(sn, s, e);
    if (qs <= m) query(lsn, s, m, qs, qe, f);
    if (qe > m) query(rsn, m + 1, e, qs, qe, f);
  }
  SegTree(int n) : SegTree(0, n - 1) {}
  SegTree(int _start, int _end) : start(_start), end(_end) {
    int n = end - start + 1;
    int maxs = n == 1 ? 2 : 1 << (33 - __builtin_clz(n - 1));
    tree.resize(maxs);
    build(1, start, end);
  }
  template <typename T>
  SegTree(vector<T>& v) {
    int n = v.size();
    int maxs = n == 1 ? 2 : 1 << (33 - __builtin_clz(n - 1));
    tree.resize(maxs);
    start = 0;
    end = n - 1;
    build(1, start, end, v);
  }
  Node query(int qs, int qe) { return query(1, start, end, qs, qe); }
  Node query(int p) { return query(1, start, end, p, p); }
  void query(int qs, int qe, const function<void(Node&, int, int)>& f) {
    if (qs > qe) return;
    query(1, start, end, qs, qe, f);
  }
  template <typename... T>
  void update(int qs, int qe, const T&... v) {
    update(1, start, end, qs, qe, v...);
  }
};
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  const int MAX = 1000001;
  vector<int> A(n), pos(MAX);
  set<int> S = {-1, MAX + 1};
  SegTree st(n);
  auto handle = [&](int i, int j, int u) {
    if (i < 0 || j < 0 || i > MAX || j > MAX) return;
    if (pos[i] > pos[j]) return;
    st.update(pos[i], pos[j] - 1, u);
  };
  auto rem = [&](int x) {
    auto it = S.find(x);
    assert(it != S.end());
    auto pit = prev(it);
    handle(*pit, x, -1);
    auto nit = next(it);
    handle(x, *nit, -1);
    handle(*pit, *nit, 1);
    S.erase(it);
  };
  auto add = [&](int x) {
    auto it = S.lower_bound(x);
    auto pit = prev(it);
    handle(*pit, *it, -1);
    handle(*pit, x, 1);
    handle(x, *it, 1);
    S.insert(x);
  };
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    pos[A[i]] = i;
    add(A[i]);
  }
  while (q--) {
    int p, x;
    scanf("%d%d", &p, &x);
    --p;
    rem(A[p]);
    A[p] = x;
    pos[x] = p;
    add(A[p]);
    if (n == 1) {
      printf("1\n");
      continue;
    }
    auto v = st.query(0, n - 2);
    int ans = v.x == 0 ? 1 + v.cnt : 1;
    printf("%d\n", ans);
  }
}

```