#include <bits/stdc++.h>
using namespace std;
inline int rei() {
  int x;
  cin >> x;
  return x;
}
inline long long rel() {
  long long x;
  cin >> x;
  return x;
}
inline string res() {
  string x;
  cin >> x;
  return x;
}
long long DP[15000015];
int A[1000001];
void Calc() {
  int N = rei();
  int M = rei();
  for (int i = 0; i < N; i++) {
    int x = rei();
    A[x]++;
  }
  for (int i = 1; i < M * 15 + 15; i++) {
    DP[i] = -1000000000;
  }
  for (int i = 1; i <= M; i++) {
    int before3 = A[i];
    for (int k = 0; k < 35; k++) {
      long long c = -1000000000;
      int after2 = k % 5;
      int after3 = k / 5;
      for (int j = 0; j < 15; j++) {
        int before1 = j % 3;
        int before2 = j / 3;
        int diff = before2 - after2;
        if (diff < 0) {
          continue;
        }
        if (diff > before1) {
          continue;
        }
        if (diff > before3 - after3) {
          continue;
        }
        if ((before3 - after3) % 3 != diff) {
          continue;
        }
        c = max(c, DP[i * 15 - 15 + j] + diff + (before3 - after3) / 3);
      }
      int k1 = k % 5;
      int k2 = k / 5;
      for (int j = 0; j < 15; j++) {
        int j1 = j % 3;
        int j2 = j / 3;
        if (j1 <= k1 && j2 <= k2) {
          DP[i * 15 + j] = max(c, DP[i * 15 + j]);
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 15; i++) {
    ans = max(ans, DP[M * 15 + i]);
  }
  cout << ans << endl;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  cout.tie(0);
  Calc();
  return 0;
}
