#include <bits/stdc++.h>
using namespace std;
long long c[1000005];
long long int dp[1000005][3][3];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    ++c[x];
  }
  long long ans = 0;
  for (long long i = 0; i <= m + 1; ++i) {
    for (long long x = 0; x <= 2; ++x) {
      for (long long y = 0; y <= 2; ++y) {
        for (long long z = 0; z <= 2; ++z) {
          if (c[i + 1] - y < z || c[i + 2] < z || c[i] - x - y < z) {
            continue;
          }
          dp[i + 1][y][z] =
              max(dp[i + 1][y][z], dp[i][x][y] + z + (c[i] - x - y - z) / 3);
          ans = max(ans, dp[i + 1][y][z]);
          ans = max(ans, dp[i][x][y]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
