#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt = 0;
  string s;
  long long int n;
  cin >> n;
  vector<long long int> ar;
  long long int b;
  for (long long int i = 0; i < n; i++) {
    cin >> b;
    ar.push_back(b);
  }
  long long int cnt = 0;
  sort(ar.begin(), ar.end());
  for (long long int i = 0; i < n - 1; i++) {
    if (ar[i + 1] - ar[i] == 1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
