#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vector<vector<T>>>;
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 998244353;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};
template <typename T, typename U>
inline bool umax(T& m, U x) {
  if (m < x) {
    m = x;
    return true;
  }
  return false;
}
template <typename T, typename U>
inline bool umin(T& m, U x) {
  if (m > x) {
    m = x;
    return true;
  }
  return false;
}
template <typename T>
inline void errv(T& v) {
  for (auto x : v) cerr << x << " ";
  cerr << endl;
}
inline void errv(vb& v) {
  for (auto x : v) cerr << (x ? 1 : 0) << " ";
  cerr << endl;
}
template <typename T>
inline void dbgn(string n, T x) {
  cerr << n << ": " << x << endl;
}
template <typename T>
inline void dbgn(string n, vector<T>& v) {
  cerr << n << ": ";
  errv(v);
}
template <typename T>
inline void dbgn(string n, vv<T>& m) {
  cerr << n << ":" << endl;
  for (auto& v : m) errv(v);
}
template <ll mod>
struct mint {
  ll x;
  mint(ll a = 0) : x((a + mod) % mod) {}
  mint operator+(mint a) { return mint(*this) += a; }
  mint operator-(mint a) { return mint(*this) -= a; }
  mint operator*(mint a) { return mint(*this) *= a; }
  mint operator/(mint a) { return mint(*this) /= a; }
  mint& operator+=(mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/=(mint a) { return *this *= a.inv(); }
  mint pow(ll t) {
    mint a = x, ret = 1;
    while (t) {
      if (t & 1) ret *= a;
      a *= a;
      t >>= 1;
    }
    return ret;
  }
  mint inv() { return pow(mod - 2); }
  friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
  friend ostream& operator<<(ostream& os, mint& a) { return os << a.x; }
};
struct UnionFind {
  vi p;
  UnionFind(int n) : p(n, -1) {}
  int root(int x) {
    if (p[x] < 0)
      return x;
    else
      return p[x] = root(p[x]);
  }
  int size(int x) { return -p[root(x)]; }
  void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return;
    if (p[rx] > p[ry]) swap(rx, ry);
    p[rx] += p[ry];
    p[ry] = rx;
  }
};
int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  for (ll i = 0; i < (n); i++) cin >> a[i];
  multiset<pii, greater<pii>> s;
  for (ll i = (n)-1; i >= 0; i--) {
    int d = -1;
    for (auto t : s) {
      if (abs(t.second - a[i]) <= 3) {
        d = t.first;
        break;
      }
    }
    if (d != -1) {
      s.insert({d + 1, a[i]});
    } else {
      s.insert({1, a[i]});
    }
  }
  cout << ((*(s.begin())).first) << endl;
  return 0;
}
