#include <bits/stdc++.h>
using namespace std;
const int N = 1000005, M = 1000000;
int n, q, a[N];
struct Value {
  int v, cnt;
};
inline Value merge(Value a, Value b) {
  Value c;
  c.v = min(a.v, b.v);
  c.cnt = (c.v == a.v) * a.cnt + (c.v == b.v) * b.cnt;
  return c;
}
struct TNode {
  int l, r;
  Value v;
} t[N << 2];
int lazy[N << 2];
inline int lc(int pos) { return pos << 1; }
inline int rc(int pos) { return pos << 1 | 1; }
inline void push(int pos, int v) {
  t[pos].v.v += v;
  lazy[pos] += v;
}
inline void pushdown(int pos) {
  push(lc(pos), lazy[pos]);
  push(rc(pos), lazy[pos]);
  lazy[pos] = 0;
}
inline void pushup(int pos) { t[pos].v = merge(t[lc(pos)].v, t[rc(pos)].v); }
bool vis[N];
void build(int pos, int l, int r) {
  t[pos].l = l;
  t[pos].r = r;
  if (l == r) {
    t[pos].v = vis[l] ? Value{0, 1} : Value{INT_MAX >> 1, 0};
    return;
  }
  int mid = (l + r) >> 1;
  build(lc(pos), l, mid);
  build(rc(pos), mid + 1, r);
  pushup(pos);
}
void modify(int pos, int l, int r, int v) {
  if (t[pos].l == l && t[pos].r == r) {
    push(pos, v);
    return;
  }
  pushdown(pos);
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (r <= mid)
    modify(lc(pos), l, r, v);
  else if (l > mid)
    modify(rc(pos), l, r, v);
  else
    modify(lc(pos), l, mid, v), modify(rc(pos), mid + 1, r, v);
  pushup(pos);
}
void modify(int pos, int p) {
  if (t[pos].l == t[pos].r) {
    t[pos].v = vis[p] ? Value{lazy[pos], 1} : Value{INT_MAX >> 1, 0};
    return;
  }
  int mid = (t[pos].l + t[pos].r) >> 1;
  pushdown(pos);
  if (p <= mid)
    modify(lc(pos), p);
  else
    modify(rc(pos), p);
  pushup(pos);
}
void ins(int pos, int v) {
  modify(1, min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]) - 1, v);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i], vis[a[i]] = 1;
  a[0] = M + 1;
  build(1, 0, M);
  for (int i = 0; i <= n; i++) ins(i, 1);
  while (q--) {
    int t1, t2;
    cin >> t1 >> t2;
    ins(t1 - 1, -1);
    ins(t1, -1);
    vis[a[t1]] = 0;
    modify(1, a[t1]);
    a[t1] = t2;
    ins(t1 - 1, 1);
    ins(t1, 1);
    vis[a[t1]] = 1;
    modify(1, a[t1]);
    cout << t[1].v.cnt << endl;
  }
  return 0;
}
