#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;
const int maxn = 1234567;
int cnt[maxn];
int dp[maxn][3][3];
void solve() {
  int n, m;
  std::cin >> n >> m;
  int t;
  for (int i = 1; i <= n; i++) {
    std::cin >> t;
    cnt[t] += 1;
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        dp[i][j][k] = 2000000;
      }
    }
  }
  int des = maxn;
  dp[0][0][0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        int k1 = min(cnt[i + 1] - j, cnt[i + 2]);
        int k2 = min(cnt[i] - j - k, 2);
        int lim = min(k1, k2);
        for (int o = 0; o <= lim; o++) {
          dp[i][o][j] =
              min(dp[i][o][j], dp[i - 1][j][k] + (cnt[i] - o - j - k) % 3);
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      des = min(des, dp[m][i][j]);
    }
  }
  std::cout << (n - des) / 3 << '\n';
}
int main(int argc, char const *argv[]) {
  solve();
  return 0;
}
