#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, ans = 0, k = 0, x;
  cin >> n;
  int f[150001 + 1] = {0}, c[150001 + 1] = {0};
  for (i = 0; i < n; i++) {
    cin >> x;
    f[x]++, c[x]++;
  }
  for (i = 1; i < 150001; i++) {
    if (f[i] == 0 && f[i + 1] != 0) {
      f[i + 1]--;
      f[i]++;
    }
  }
  for (i = 150000; i > 0; i--) {
    if (f[i] != 0 && f[i + 1] == 0) {
      f[i + 1]++;
      f[i]--;
    }
  }
  for (i = 0; i < 150001 + 1; i++) ans += (f[i] > 0);
  for (i = 150000; i > 0; i--) {
    if (c[i] != 0 && c[i + 1] == 0) {
      c[i + 1]++;
      c[i]--;
    }
  }
  for (i = 1; i < 150001; i++) {
    if (c[i] == 0 && c[i + 1] != 0) {
      c[i + 1]--;
      c[i]++;
    }
  }
  for (i = 0; i < 150001 + 1; i++) k += (c[i] > 0);
  ans = max(ans, k);
  cout << ans;
}
