#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long Hashimoto = 0;
  bool Kanna = 1;
  char I_Love = getchar();
  while (I_Love < '0' || I_Love > '9') {
    if (I_Love == '-') Kanna = 0;
    I_Love = getchar();
  }
  while (I_Love >= '0' && I_Love <= '9') {
    Hashimoto = Hashimoto * 10 + I_Love - '0';
    I_Love = getchar();
  }
  return (Kanna ? Hashimoto : -Hashimoto);
}
template <typename T1, typename T2>
inline void Umax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void Umin(T1 &a, T2 b) {
  if (a > b) a = b;
}
int n, m;
int a[1111111];
vector<pair<int, int> > s;
int dp[2][10][10];
int calc() {
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  int cur = 0, nxt = 1;
  dp[0][0][0] = 0;
  for (int i = 0; i < (s.size()); ++i) {
    memset(dp[nxt], -1, sizeof(dp[nxt]));
    for (int j = 0; j < (10); ++j)
      for (int k = 0; k < (10); ++k)
        if (dp[cur][j][k] != -1) {
          int num = j + k;
          num = s[i].second - num;
          for (int nx = 0; nx < (4); ++nx)
            for (int ny = 0; ny < (10); ++ny)
              if (nx * 3 + ny <= num) {
                dp[nxt][k][ny] = max(dp[nxt][k][ny], dp[cur][j][k] + j + nx);
              }
        }
    swap(cur, nxt);
  }
  for (int i = 0; i < (10); ++i)
    for (int j = 0; j < (10); ++j) ans = max(ans, dp[cur][i][j]);
  s.clear();
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  m = read();
  n = read();
  for (int i = 0; i < (m); ++i) {
    int x = read() - 1;
    a[x]++;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (a[i] == 0) continue;
    if (a[i] > 9) {
      if (a[i] % 3 == 0)
        ans += a[i] / 3 - 3, a[i] = 9;
      else
        ans += a[i] / 3 - 2, a[i] = a[i] % 3 + 6;
    }
    if (s.size() == 0) {
      s.push_back(make_pair(i, a[i]));
    } else {
      if (i == s[s.size() - 1].first + 1)
        s.push_back(make_pair(i, a[i]));
      else
        ans += calc(), s.push_back(make_pair(i, a[i]));
    }
  }
  if (s.size()) ans += calc();
  cout << ans << endl;
  ;
  return 0;
}
