#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 = 1000;
    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 = bsh(0, (int)block.size() - 1, [&](int first) {
            return !Groups.empty() && 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;
                });
                last.lo = lastB[s - 1].first;
                last.hi = lastB[last.from].second;
                BG.lo = min(BG.lo, lastB[last.to - 1].first);
                BG.hi = max(BG.hi, lastB[s].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;
}
