#include <bits/stdc++.h>
using namespace std;
vector<int> twoadd(vector<int> v, int N) {
  v[N - 1] += 1;
  int ind = N - 1;
  int j = N - 1;
  for (j = N - 1; j >= 1; j--) {
    if (v[j] > 1) {
      v[j - 1] += 1;
      v[j] = 0;
    }
  }
  return v;
}
long long fibonatti(long long d) {
  long long count = 0;
  long long f1 = 1;
  long long f2 = 1;
  long long temp;
  if (d == 1) {
    count = f1;
  } else if (d == 2) {
    count = f2;
  } else if (d == 0) {
    count = 1;
  } else {
    for (int i = 0; i < d - 2; i++) {
      temp = f1 + f2;
      f1 = f2;
      f2 = temp;
    }
    count = temp;
  }
  return count;
}
unsigned long long GCD(long long L, long long R) {
  if (L > R) {
    long long temp = R;
    R = L;
    L = temp;
  }
  unsigned long long pp = 0, ppt = 0;
  unsigned long long ans = 0;
  if (R % L == 0) {
    ans = L;
  } else {
    while (true) {
      ppt = pp;
      pp = R % L;
      if (pp == 0) {
        ans = ppt;
        break;
      }
      R = L;
      L = pp;
    }
  }
  return ans;
}
unsigned long long LCM(long long L, long long R) {
  unsigned long long ans;
  unsigned long long gcd = GCD(L, R);
  ans = (L / gcd) * R;
  return ans;
}
vector<long long> fc(3000 + 1);
vector<long long> ifc(3000 + 1);
long long modpow(long long x, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x % 1000000007;
    }
    x = x * x % 1000000007;
    n >>= 1;
  }
  return ans;
}
void Conb() {
  fc[0] = 1;
  ifc[0] = 1;
  for (long long i = 0; i < 3000; i++) {
    fc[i + 1] = fc[i] * (i + 1) % 1000000007;
    ifc[i + 1] = ifc[i] * modpow(i + 1, 1000000007 - 2) % 1000000007;
  }
}
unsigned long long Combination(long long L, long long R) {
  unsigned long long up = 1, ans;
  Conb();
  if (L == 0 && R == 0) {
    return 1;
  } else if (L < R || L < 0) {
    return 0;
  } else {
    long long t = ifc[L - R] * ifc[R] % 1000000007;
    ans = t * fc[L] % 1000000007;
  }
  return ans;
}
bool isPrime(int x) {
  int i;
  if (x < 2) {
    return 0;
  } else if (x == 2) {
    return 1;
  }
  if (x % 2 == 0) {
    return 0;
  }
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      return 0;
    }
  }
  return 1;
}
int digsum(int n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
long long countdivisor(long long K) {
  long long N = sqrt(K);
  bool b = false;
  if (sqrt(K) - N == 0) {
    b = true;
  }
  long long count = 0;
  for (int i = 0; i < N; i++) {
    if (K % (i + 1) == 0) {
      count++;
    }
  }
  if (b == false) {
    count *= 2;
  } else {
    count = (count - 1) * 2 + 1;
  }
  return count;
}
vector<long> Alldivisor(long n) {
  vector<long> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}
int stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
long countYak(long long K) {
  long N = sqrt(K);
  bool b = false;
  if (sqrt(K) - N == 0) {
    b = true;
  }
  long count = 1;
  if (K == 1) {
    return 1;
  }
  if (K == 2) {
    return 2;
  }
  if (K == 3) {
    return 2;
  }
  if (K == 4) {
    return 3;
  }
  if (K == 6) {
    return 4;
  }
  if (K % 2 != 0) {
    if (K % 3 != 0) {
      for (int i = 4; i < N; i += 2) {
        if (K % (i + 1) == 0) {
          count++;
        }
      }
    } else {
      count += 1;
      for (int i = 4; i < N; i += 2) {
        if (K % (i + 1) == 0) {
          count++;
        }
      }
    }
  } else {
    count += 1;
    if (K % 3 != 0) {
      for (int i = 3; i < N; i++) {
        if (K % (i + 1) == 0) {
          count++;
        }
      }
    } else {
      count += 1;
      for (int i = 3; i < N; i++) {
        if (K % (i + 1) == 0) {
          count++;
        }
      }
    }
  }
  if (b == false) {
    count *= 2;
  } else {
    count = (count - 1) * 2 + 1;
  }
  return count;
}
using Graph = vector<vector<int>>;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using WGraph = vector<vector<Edge>>;
Graph WeightlessGraph(int N, int M) {
  Graph G(N);
  vector<bool> m(N, false);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
  }
  return G;
}
Graph WeightlessNoDirectionGraph(int N, int M) {
  Graph G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  return G;
}
WGraph WeightGraph(int N, int M) {
  WGraph G(N);
  for (int i = 0; i < M; i++) {
    int from, to, weight;
    cin >> from >> to >> weight;
    G[from].push_back(Edge(to, weight));
  }
  return G;
}
vector<bool> seen;
void dfs(const Graph &G, int s, int p) {
  seen[s] = true;
  for (auto next_v : G[s]) {
    if (seen[next_v]) {
      continue;
    }
    dfs(G, next_v, s);
  }
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int k = 0;
  int count = 0, countans = 0;
  vector<int> B(N, -1);
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (j == i) {
        B[0] = A[i];
        k++;
      }
      if (abs(A[j] - B[k - 1]) <= 3) {
        B[k] = A[j];
        k++;
        count++;
      }
    }
    if (count > countans) {
      countans = count;
    }
    if (countans >= N - i) {
      break;
    }
    count = 0;
    k = 0;
    B.assign(N, -1);
  }
  cout << countans << endl;
  return 0;
}
