#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  int tmp, m = 1;
  for (int i = 1; i <= n; i++) {
    int b;
    cin >> b;
    if (i == 1) {
      v.push_back(b);
      tmp = b;
    } else {
      if (abs(tmp - b) <= 3) {
        v.push_back(b);
        tmp = b;
      }
    }
  }
  if (abs(v[0] - v[v.size() - 1]) > 3)
    cout << v.size() - 1 << endl;
  else
    cout << v.size() << endl;
  return 0;
}
