#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
  for (auto& v : t) {
    i >> v;
  }
  return i;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {
  o << p.first << ' ' << p.second;
  return o;
}
template <typename T>
std::ostream& operator<<(std::ostream& o, const vector<T>& t) {
  if (t.empty()) o << '\n';
  for (size_t i = 0; i < t.size(); ++i) {
    o << t[i] << " \n"[i == t.size() - 1];
  }
  return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
unsigned int logceil(long long first) {
  return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;
}
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
  hash<T> t;
  hash<U> u;
  size_t operator()(const pair<T, U>& p) const {
    return t(p.first) ^ (u(p.second) << 7);
  }
};
}  // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      l = m + 1;
      r = m;
    } else {
      h = m - 1;
    }
  }
  return r;
}
template <typename F>
double bshd(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      l = m;
    } else {
      h = m;
    }
  }
  return (l + h) / 2;
}
template <typename T, typename F>
T bsl(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      h = m - 1;
      r = m;
    } else {
      l = m + 1;
    }
  }
  return r;
}
template <typename F>
double bsld(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      h = m;
    } else {
      l = m;
    }
  }
  return (l + h) / 2;
}
template <typename T>
T gcd(T a, T b) {
  if (a < b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}
template <typename T>
class vector2 : public vector<vector<T>> {
 public:
  vector2() {}
  vector2(size_t a, size_t b, T t = T())
      : vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T>
class vector3 : public vector<vector2<T>> {
 public:
  vector3() {}
  vector3(size_t a, size_t b, size_t c, T t = T())
      : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T>
class vector4 : public vector<vector3<T>> {
 public:
  vector4() {}
  vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
      : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T>
class vector5 : public vector<vector4<T>> {
 public:
  vector5() {}
  vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
      : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
class HNumberOfComponents {
 public:
  int N, Q;
  vector<int> A;
  void build(vector<std::pair<int, int>>& block, int from, int to) {
    block.clear();
    for (int i = from; i < to; ++i) {
      std::pair<int, int> c = {A[i], A[i]};
      while (!block.empty() && block.back().first < c.second) {
        c = {min(block.back().first, c.first),
             max(block.back().second, c.second)};
        block.pop_back();
      }
      block.push_back(c);
    }
  }
  vector<vector<std::pair<int, int>>> Blocks;
  struct BlockGroup {
    int blockId;
    int from, to;
    int lo, hi;
  };
  void solve(istream& cin, ostream& cout) {
    cin >> N >> Q;
    A.resize(N);
    cin >> A;
    int S = 1024;
    int B = (N + S - 1) / S;
    Blocks.resize(B);
    for (int i = 0; i < B; ++i) {
      build(Blocks[i], i * S, min(i * S + S, N));
    }
    for (int q = 0; q < Q; ++q) {
      int p, first;
      cin >> p >> first;
      --p;
      int b = p / S;
      A[p] = first;
      build(Blocks[b], b * S, min(N, b * S + S));
      vector<BlockGroup> Groups;
      for (int i = 0; i < B; ++i) {
        auto& block = Blocks[i];
        if (Groups.empty() || Groups.back().lo >= block[0].second) {
          Groups.push_back(BlockGroup{i, 0, (int)block.size(),
                                      block.back().first, block[0].second});
        } else {
          int j = (Groups.back().lo < block[(int)block.size() - 1].second)
                      ? (int)block.size() - 1
                      : bsh(0, (int)block.size() - 1, [&](int first) {
                          return Groups.back().lo < block[first].second;
                        });
          BlockGroup BG{-1, 0, 1, block.back().first, block[0].second};
          while (!Groups.empty() && Groups.back().lo < BG.hi) {
            auto& last = Groups.back();
            if (last.blockId == -1) {
              BG.lo = min(BG.lo, last.lo);
              BG.hi = max(BG.hi, last.hi);
              Groups.pop_back();
            } else {
              auto& lastB = Blocks[last.blockId];
              if (lastB[last.from].first < BG.hi) {
                BG.lo = min(BG.lo, last.lo);
                BG.hi = max(BG.hi, last.hi);
                Groups.pop_back();
              } else {
                int s = bsl(last.from, last.to - 1, [&](int first) {
                  return lastB[first].first < BG.hi;
                });
                BG.lo = min(BG.lo, lastB[last.to - 1].first);
                BG.hi = max(BG.hi, lastB[s].second);
                last.lo = lastB[s - 1].first;
                last.hi = lastB[last.from].second;
                last.to = s;
              }
            }
          }
          Groups.push_back(BG);
          if (j + 1 != (int)block.size()) {
            Groups.push_back(BlockGroup{i, j + 1, (int)block.size(),
                                        block.back().first,
                                        block[j + 1].second});
          }
        }
      }
      int ans = 0;
      for (BlockGroup& bg : Groups) ans += bg.to - bg.from;
      cout << ans << '\n';
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  HNumberOfComponents solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

### Prompt

Create a solution in cpp for 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, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
  for (auto& v : t) {
    i >> v;
  }
  return i;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {
  o << p.first << ' ' << p.second;
  return o;
}
template <typename T>
std::ostream& operator<<(std::ostream& o, const vector<T>& t) {
  if (t.empty()) o << '\n';
  for (size_t i = 0; i < t.size(); ++i) {
    o << t[i] << " \n"[i == t.size() - 1];
  }
  return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
unsigned int logceil(long long first) {
  return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;
}
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
  hash<T> t;
  hash<U> u;
  size_t operator()(const pair<T, U>& p) const {
    return t(p.first) ^ (u(p.second) << 7);
  }
};
}  // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      l = m + 1;
      r = m;
    } else {
      h = m - 1;
    }
  }
  return r;
}
template <typename F>
double bshd(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      l = m;
    } else {
      h = m;
    }
  }
  return (l + h) / 2;
}
template <typename T, typename F>
T bsl(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      h = m - 1;
      r = m;
    } else {
      l = m + 1;
    }
  }
  return r;
}
template <typename F>
double bsld(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      h = m;
    } else {
      l = m;
    }
  }
  return (l + h) / 2;
}
template <typename T>
T gcd(T a, T b) {
  if (a < b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}
template <typename T>
class vector2 : public vector<vector<T>> {
 public:
  vector2() {}
  vector2(size_t a, size_t b, T t = T())
      : vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T>
class vector3 : public vector<vector2<T>> {
 public:
  vector3() {}
  vector3(size_t a, size_t b, size_t c, T t = T())
      : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T>
class vector4 : public vector<vector3<T>> {
 public:
  vector4() {}
  vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
      : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T>
class vector5 : public vector<vector4<T>> {
 public:
  vector5() {}
  vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
      : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
class HNumberOfComponents {
 public:
  int N, Q;
  vector<int> A;
  void build(vector<std::pair<int, int>>& block, int from, int to) {
    block.clear();
    for (int i = from; i < to; ++i) {
      std::pair<int, int> c = {A[i], A[i]};
      while (!block.empty() && block.back().first < c.second) {
        c = {min(block.back().first, c.first),
             max(block.back().second, c.second)};
        block.pop_back();
      }
      block.push_back(c);
    }
  }
  vector<vector<std::pair<int, int>>> Blocks;
  struct BlockGroup {
    int blockId;
    int from, to;
    int lo, hi;
  };
  void solve(istream& cin, ostream& cout) {
    cin >> N >> Q;
    A.resize(N);
    cin >> A;
    int S = 1024;
    int B = (N + S - 1) / S;
    Blocks.resize(B);
    for (int i = 0; i < B; ++i) {
      build(Blocks[i], i * S, min(i * S + S, N));
    }
    for (int q = 0; q < Q; ++q) {
      int p, first;
      cin >> p >> first;
      --p;
      int b = p / S;
      A[p] = first;
      build(Blocks[b], b * S, min(N, b * S + S));
      vector<BlockGroup> Groups;
      for (int i = 0; i < B; ++i) {
        auto& block = Blocks[i];
        if (Groups.empty() || Groups.back().lo >= block[0].second) {
          Groups.push_back(BlockGroup{i, 0, (int)block.size(),
                                      block.back().first, block[0].second});
        } else {
          int j = (Groups.back().lo < block[(int)block.size() - 1].second)
                      ? (int)block.size() - 1
                      : bsh(0, (int)block.size() - 1, [&](int first) {
                          return Groups.back().lo < block[first].second;
                        });
          BlockGroup BG{-1, 0, 1, block.back().first, block[0].second};
          while (!Groups.empty() && Groups.back().lo < BG.hi) {
            auto& last = Groups.back();
            if (last.blockId == -1) {
              BG.lo = min(BG.lo, last.lo);
              BG.hi = max(BG.hi, last.hi);
              Groups.pop_back();
            } else {
              auto& lastB = Blocks[last.blockId];
              if (lastB[last.from].first < BG.hi) {
                BG.lo = min(BG.lo, last.lo);
                BG.hi = max(BG.hi, last.hi);
                Groups.pop_back();
              } else {
                int s = bsl(last.from, last.to - 1, [&](int first) {
                  return lastB[first].first < BG.hi;
                });
                BG.lo = min(BG.lo, lastB[last.to - 1].first);
                BG.hi = max(BG.hi, lastB[s].second);
                last.lo = lastB[s - 1].first;
                last.hi = lastB[last.from].second;
                last.to = s;
              }
            }
          }
          Groups.push_back(BG);
          if (j + 1 != (int)block.size()) {
            Groups.push_back(BlockGroup{i, j + 1, (int)block.size(),
                                        block.back().first,
                                        block[j + 1].second});
          }
        }
      }
      int ans = 0;
      for (BlockGroup& bg : Groups) ans += bg.to - bg.from;
      cout << ans << '\n';
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  HNumberOfComponents solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

```