#include <bits/stdc++.h>
inline int in();
inline void wr(int);
const int N = (int)2e5 + 5;
int a[N];
int main(int argc, char** argv) {
  register int n = in();
  for (register int i = 1; i <= n; ++i) a[i] = in();
  std::sort(a + 1, a + 1 + n);
  for (register int i = 1, j = 1; i < N; ++i, ++j) {
    while (a[j] < i && j + 1 <= n) ++j;
    if (a[j] < i) {
      wr(i - 1);
      return 0;
    }
  }
}
inline int in() {
  register char c = getchar();
  register int x = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c & 15);
  return x * f;
}
inline void wr(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x / 10) wr(x / 10);
  putchar(x % 10 + '0');
}
