#include <iostream>
#include <unordered_set>
using namespace std;
unordered_set<int> s;
int main(){
int n, ans = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++){
int x;
scanf("%d", &x);
if(s.count(x - 1)) ans++;
if(s.count(x + 1)) ans++;
s.insert(x);
}
cout << ans;
return 0;
}