#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000000 + 10;
long long dp[MAXN][3][3][3];
int n, m;
long long num[MAXN];
void solve() {
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          if (j + k + l > num[i] || k + l > num[i + 1] || l > num[i + 2]) {
            dp[i][j][k][l] = 0;
            break;
          }
          for (int y = 0; y < 3; y++) {
            dp[i][j][k][l] = max(dp[i][j][k][l], dp[i - 1][y][j][k]);
          }
          dp[i][j][k][l] += (num[i] - j - k - l) / 3 + l;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 3; i++) {
    ans = max(ans, dp[m][i][0][0]);
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d %d", &n, &m);
  int a;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    num[a]++;
  }
  solve();
  return 0;
}
