#include <bits/stdc++.h>
using namespace std;
int cnt[1000010], n, m;
int dp[1000010][5][5];
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= 4; j++) {
      for (int k = 0; k <= 4; k++) {
        if (dp[i - 1][j][k] == -1) continue;
        int minv = min(j, k);
        for (int l = 0; l <= minv; l++) {
          int val = cnt[i] - l;
          if (val < 0) break;
          int num = val / 3, rem = val % 3;
          dp[i][rem][j - l] = max(dp[i][rem][j - l], dp[i - 1][j][k] + num + l);
          if (num > 0) {
            dp[i][min(4, rem + 3)][j - l] = max(dp[i][min(4, rem + 3)][j - l],
                                                dp[i - 1][j][k] + num - 1 + l);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 4; i++) {
    for (int j = 0; j <= 4; j++) {
      ans = max(ans, dp[m][i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
