#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n;
  vector<long long> v(150005, 0);
  for (unsigned long long i = 0; i < n; i++) cin >> x, v[x]++;
  int lp = 0, need = 0;
  int ans = 0;
  for (int i = 1; i <= 150001; i++) {
    if (v[i] == 0) {
      if (need) {
        ans++;
        need = 0;
      } else
        lp = 1;
    } else if (v[i] == 1) {
      ans++;
      continue;
    } else {
      ans++;
      if (v[i] == 2) {
        if (lp) {
          lp = 0;
          ans++;
        } else
          need = 1;
      } else {
        if (lp) {
          lp = 0;
          ans++;
        }
        need = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
