Open KATO-Hiro opened 1 year ago
# Usage
# See: https://atcoder.jp/contests/abc330/submissions/48019651
def main():
import sys
from collections import defaultdict
input = sys.stdin.readline
n, q = map(int, input().split())
a = list(map(int, input().split()))
b = BITSet(n + 1)
d = defaultdict(int)
# mex: [0, n]の範囲なので、n + 1以上はn + 1として処理
for ai in a:
d[min(ai, n + 1)] += 1
for key in d.keys():
b.add(key)
for _ in range(q):
i, xi = map(int, input().split())
i -= 1
xi = min(xi, n + 1)
# remove
d[a[i]] -= 1
if d[a[i]] == 0:
b.remove(a[i])
# add
a[i] = xi
d[xi] += 1
if d[xi] == 1:
b.add(xi)
print(b.mex())
if __name__ == "__main__":
main()