队列 + 字典
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
queue<int> que;
const int N = 1005;
bool dict[N];
int main () {
int m,n,cnt = 0;
cin >> m >> n;
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
if (!dict[x]) {
cnt++;
que.push(x);
dict[x] = true;
if (que.size() > m) {
dict[que.front()] = false;
que.pop();
}
}
}
cout << cnt << endl;
}