#include <iostream>
#include <map>
using namespace std;
map < int, int > p;
int main() {
int n, m;
int a[100001] = {};
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
p[a[i]]++;
}
int ans = 0;
int x = 0;
for (int i = 0; i < m; i++) {
x = 0;
for (int j = 0; n >= m - i && p[j]; j++) {
x++;
n--;
p[j]--;
}
ans += x;
}
cout << ans;
}