C++ code :
#include <bits/stdc++.h>
using namespace std;
int main()
{
// your code goes here
int n, k;
cin >> n >> k;
vector<int> arr;
// int temp = 0;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
// vector<pair<int, int>> queries;
int temp1, temp2;
unordered_map<int, int> mp;
for (int i = 0; i < n; i++)
{
mp[arr[i]]++;
}
for (int i = 0; i < k; i++)
{
cin >> temp1 >> temp2;
// queries.push_back({temp1, temp2});
mp[arr[temp1]]--;
arr[temp1] = temp2;
mp[arr[temp1]]++;
int ans = 0;
for (auto it : mp)
{
if (it.second == 1)
ans++;
}
cout << ans << " ";
}
return 0;
}