#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int a[maxn], cnt[maxn], dp[maxn][3][3];
int n, m;
void init() {
  memset(cnt, 0, sizeof(cnt)), memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
}
int main() {
  while (cin >> n >> m) {
    init();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      cnt[a[i]]++;
    }
    for (int i = 0; i <= m - 1; i++) {
      for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
          if (x + y > cnt[i] || dp[i][x][y] == -1) continue;
          for (int t = 0; t < 3; t++) {
            if (x + y + t > cnt[i + 1]) continue;
            int le = cnt[i + 1] - x - y - t;
            dp[i + 1][t][x] = max(dp[i + 1][t][x], dp[i][x][y] + y + le / 3);
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        ans = max(ans, dp[m][i][j]);
      }
    }
    printf("%d\n", ans);
  }
}
