#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T>
void read(T &x) {
  x = 0;
  int c = getchar();
  int flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
template <class T>
T _max(T a, T b) {
  return b < a ? a : b;
}
template <class T>
T _min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
bool checkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
const int N = 500005, V = 1000000, inf = 0x3f3f3f3f, Node = (V + 5) << 2;
int n, q;
int a[N];
int exist[Node], tag[Node], Min[Node], mincnt[Node];
void push_up(int x) {
  int ls = x << 1, rs = x << 1 | 1;
  if (!exist[ls] && !exist[rs]) {
    exist[x] = 0;
    Min[x] = 0, mincnt[x] = 1;
    return;
  }
  exist[x] = 1;
  if (!exist[rs])
    Min[x] = Min[ls], mincnt[x] = mincnt[ls];
  else if (!exist[ls])
    Min[x] = Min[rs], mincnt[x] = mincnt[rs];
  else if (Min[ls] < Min[rs])
    Min[x] = Min[ls], mincnt[x] = mincnt[ls];
  else if (Min[ls] > Min[rs])
    Min[x] = Min[rs], mincnt[x] = mincnt[rs];
  else
    Min[x] = Min[ls], mincnt[x] = mincnt[ls] + mincnt[rs];
}
void push_tag(int x, int c) {
  Min[x] += c;
  tag[x] += c;
}
void push_down(int x) {
  if (tag[x]) {
    push_tag(x << 1, tag[x]);
    push_tag(x << 1 | 1, tag[x]);
    tag[x] = 0;
  }
}
void build(int x, int l, int r) {
  tag[x] = 0;
  if (l == r) {
    Min[x] = exist[x] = 0;
    mincnt[x] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  push_up(x);
}
void update(int x, int l, int r, int L, int R, int c) {
  if (L <= l && r <= R) {
    push_tag(x, c);
    return;
  }
  push_down(x);
  int mid = (l + r) >> 1;
  if (L <= mid) update(x << 1, l, mid, L, R, c);
  if (R > mid) update(x << 1 | 1, mid + 1, r, L, R, c);
  push_up(x);
}
void update(int x, int y, int c) {
  if (x > y) return;
  update(1, 1, V, x, y, c);
}
void change(int x, int l, int r, int pos, int c) {
  if (l == r) {
    exist[x] = c;
    return;
  }
  push_down(x);
  int mid = (l + r) >> 1;
  if (pos <= mid)
    change(x << 1, l, mid, pos, c);
  else
    change(x << 1 | 1, mid + 1, r, pos, c);
  push_up(x);
}
int query(int x, int l, int r, int pos) {
  if (l == r) {
    return Min[x];
  }
  push_down(x);
  int mid = (l + r) >> 1;
  if (pos <= mid)
    return query(x << 1, l, mid, pos);
  else
    return query(x << 1 | 1, mid + 1, r, pos);
}
void init() {
  read(n);
  read(q);
  for (int i = 1; i <= n; ++i) read(a[i]);
  a[0] = V + 1, a[n + 1] = 1;
  build(1, 1, V);
  for (int i = 0; i <= n; ++i) update(a[i + 1], a[i] - 1, 1);
  for (int i = 1; i <= n; ++i) change(1, 1, V, a[i], 1);
}
void solve() {
  int x, y;
  while (q--) {
    read(x);
    read(y);
    change(1, 1, V, a[x], 0);
    update(a[x], a[x - 1] - 1, -1);
    update(a[x + 1], a[x] - 1, -1);
    a[x] = y;
    change(1, 1, V, a[x], 1);
    update(a[x], a[x - 1] - 1, 1);
    update(a[x + 1], a[x] - 1, 1);
    printf("%d\n", Min[1] == 1 ? mincnt[1] : 0);
  }
}
int main() {
  init();
  solve();
  return 0;
}
