#include <bits/stdc++.h>
using namespace std;
const char NL = '\n';
const char SP = ' ';
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    m[c]++;
  }
  int i = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    bool g = true;
    for (int j = 1; j <= it->second && g; j++) {
      if (it->first >= i + 1) {
        i++;
      } else {
        g = false;
      }
    }
  }
  cout << i << NL;
  return 0;
}
