#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
inline long long int add(long long int x, long long int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline long long int sub(long long int x, long long int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline long long int mul(long long int x, long long int y) {
  return ((x % mod) * (y % mod)) % mod;
}
inline long long int power(long long int a, long long int b) {
  long long int x = 1;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline long long int inv(long long int a) { return power(a, mod - 2); }
const long long int N = 1e6 + 6;
long long int dp[N][4][4], cnt[N], n, m;
long long int f(long long int i, long long int cur, long long int nxt) {
  if (i >= m - 1) {
    return ((cnt[i] - cur) / 3 + (cnt[i + 1] - nxt) / 3);
  }
  long long int &ret = dp[i][cur][nxt];
  if (ret != -1) return ret;
  ret = 0;
  ret = max(ret, (cnt[i] - cur) / 3 + f(i + 1, nxt, 0));
  if ((cnt[i] - cur) >= 1 and (cnt[i + 1] - nxt) >= 1 and cnt[i + 2] >= 1) {
    ret = max(ret, 1 + (cnt[i] - 1 - cur) / 3 + f(i + 1, nxt + 1, 1));
  }
  if ((cnt[i] - cur) >= 2 and (cnt[i + 1] - nxt) >= 2 and cnt[i + 2] >= 2) {
    ret = max(ret, 2 + (cnt[i] - 2 - cur) / 3 + f(i + 1, nxt + 2, 2));
  }
  dp[i][cur][nxt] = ret;
  return ret;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) {
    long long int x;
    cin >> x;
    cnt[x]++;
  }
  memset(dp, -1, sizeof dp);
  cout << f(1, 0, 0);
  return 0;
}
