#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int dp[N + 100][3][3], cnt[N + 100];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int cur;
    scanf("%d", &cur);
    cnt[cur]++;
  }
  for (int i = 1; i <= m; i++) {
    for (int x = 0; x < 3; x++) {
      for (int y = 0; y < 3; y++) {
        for (int z = 0; z < 3; z++) {
          if (cnt[i] >= x + y + z && cnt[i + 1] >= y + z && cnt[i + 2] >= z) {
            dp[i][y][z] = max(dp[i][y][z],
                              dp[i - 1][x][y] + z + (cnt[i] - x - y - z) / 3);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        ans = max(ans, dp[i][j][k]);
      }
    }
  }
  printf("%d\n", ans);
}
