#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 1e6 + 9;
int arr[N];
long long dp[N][4][4];
long long solve(int ind, int next, int nextt) {
  if (ind == m) {
    return 0;
  }
  int cur = arr[ind] - next;
  int f = arr[ind + 1] - nextt;
  if (~dp[ind][next][nextt]) return dp[ind][next][nextt];
  if (m - ind == 1) {
    return dp[ind][next][nextt] = cur / 3 + f / 3;
  }
  long long a = solve(ind + 1, nextt, 0) + cur / 3;
  int mn = min(cur, min(f, arr[ind + 2]));
  for (int i = 0; i <= 2; i++) {
    if (i > mn) break;
    a = max(a, solve(ind + 1, nextt + i, i) + (cur - i) / 3 + i);
  }
  return dp[ind][next][nextt] = a;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    arr[x]++;
  }
  if (m < 3) {
    cout << arr[1] / 3 + arr[2] / 3;
    return 0;
  }
  cout << solve(1, 0, 0);
  return 0;
}
