Problem:
Score : 1000 points

Problem Statement

There are N balls in a row.
Initially, the i-th ball from the left has the integer A_i written on it.

When Snuke cast a spell, the following happens:

Let the current number of balls be k. All the balls with k written on them disappear at the same time.

Snuke's objective is to vanish all the balls by casting the spell some number of times.
This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable.

By the way, the integers on these balls sometimes change by themselves.
There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j.

After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.

Constraints

1 \leq N \leq 200000

1 \leq M \leq 200000

1 \leq A_i \leq N

1 \leq X_j \leq N

1 \leq Y_j \leq N

Subscore

In the test set worth 500 points, N \leq 200 and M \leq 200.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N
X_1 Y_1
X_2 Y_2
:
X_M Y_M

Output

Print M lines.
The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable.

Sample Input 1

5 3
1 1 3 4 5
1 2
2 5
5 4

Sample Output 1

0
1
1

After the first change, the integers on the balls become 2, 1, 3, 4, 5, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.

After the second change, the integers on the balls become 2, 5, 3, 4, 5, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.

After the third change, the integers on the balls become 2, 5, 3, 4, 4, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.

Sample Input 2

4 4
4 4 4 4
4 1
3 1
1 1
2 1

Sample Output 2

0
1
2
3

Sample Input 3

10 10
8 7 2 9 10 6 6 5 5 4
8 1
6 3
6 2
7 10
9 7
9 9
2 4
8 1
1 8
7 7

Sample Output 3

1
0
1
2
2
3
3
3
3
2

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll inf = 1e15;

// Reference: http://mmxsrup.hatenablog.com/category/%E9%81%85%E5%BB%B6%E8%A9%95%E4%BE%A1%E3%82%BB%E3%82%B0%E3%83%A1%E3%83%B3%E3%83%88%E6%9C%A8
// with a little modification (add, min)
//(1)区間に一様加算 (2)区間の合計値
struct segtree{
public:
    const int SIZE = 1 << 18;
    //seg:区間の合計値 lazy:区間に対して、加える値でまだ遅延しているもの
    vector<ll> seg, lazy;//segは欲しい情報 lazyは区間に対する一様な処理を示すもの
    segtree():seg(SIZE * 2), lazy(SIZE * 2){}
    void lazy_evaluate(int k, int l, int r){//遅延情報の適用方法
        if(lazy[k] != 0){
            seg[k] += lazy[k];//区間[l,r)にすべて同じ値を追加することになっていて、segには合計値が入っているので、加える値を足す
            if(r  - l > 1){
                lazy[k * 2 + 1] += lazy[k];//遅延を左の子に伝搬
                lazy[k * 2 + 2] += lazy[k];//遅延を右の子に伝搬
            }
            lazy[k] = 0;//ノードkは伝搬完了
        }
    }
    void update(int a, int b, int k, int l, int r, ll x){
        lazy_evaluate(k, l, r);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            lazy[k] += x; //加える
            lazy_evaluate(k, l, r);
        }else{
            update(a, b, k * 2 + 1, l, (l + r) / 2, x);
            update(a, b, k * 2 + 2, (l + r) / 2, r, x);
            seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]); //区間の合計
        }
    }  
    ll query(int a, int b, int k, int l, int r){
        lazy_evaluate(k, l, r);
        if(r <= a || b <= l) return inf;//合計に影響のないもの
        if(a <= l && r <= b) return seg[k];
        ll x = query(a, b, k * 2 + 1, l, (l + r) / 2);
        ll y = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(x, y); //左右の合計を
    }
    //update(a,b,x) := [a,b)を全てxを加える
    void update(int a, int b, ll x){update(a, b, 0, 0, SIZE, x);}
    //query(a,b) := [a,b)に対する合計値を求める
    ll query(int a, int b){return query(a, b, 0, 0, SIZE);}
};




int main(void){
  int n, m;
  cin >> n >> m;
  VI a(n), x(m), y(m);
  VI f(n + 1, 0);
  REP(i, 0, n) {
    cin >> a[i];
    f[a[i]] += 1;
  }
  REP(i, 0, m) {
    cin >> x[i] >> y[i];
    x[i]--;
  }
  // h[k] := f[1] + ... + f[k] - k
  segtree h;
  segtree hneg;
  ll cur = 0;
  REP(i, 0, n + 1) {
    h.update(i, i + 1, cur);
    hneg.update(i, i + 1, -cur);
    if (i == n) {
      break;
    }
    cur += f[i + 1];
    cur -= 1;
  }
  REP(i, 1, n + 1) {
    if (f[i] == 0) {
      h.update(i, i + 1, inf);
      hneg.update(i, i + 1, inf);
    }
  }
  REP(i, 0, m) {
    if (0) {
      cerr << "h:";
      REP(i, 0, n + 1) {
	cerr << " " << h.query(i, i + 1);
      }
      cerr << endl;
    }
    int olda = a[x[i]];
    a[x[i]] = y[i];
    h.update(olda, n + 1, -1);
    h.update(y[i], n + 1, 1);
    hneg.update(olda, n + 1, 1);
    hneg.update(y[i], n + 1, -1);
    f[olda] -= 1;
    if (f[olda] == 0) {
      h.update(olda, olda + 1, inf);
      hneg.update(olda, olda + 1, inf);
    }
    f[y[i]] += 1;
    if (f[y[i]] == 1) {
      h.update(y[i], y[i] + 1, -inf);
      hneg.update(y[i], y[i] + 1, -inf);
    }
    ll res = -h.query(1, n + 1);
    ll res2 = -hneg.query(1, n + 1);
    cout << max(0LL, res2) + max(res, 0LL) << endl;;
  }
  
}