#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 1000005
using namespace std;
int dp[maxn][3][3],cnt[maxn],a[maxn],n,m;
int main()
{
int i,j,k,t,lim;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
{
scanf("%d",&a[i]);
cnt[a[i]]++;
}
memset(dp,-1,sizeof(dp));
dp[0][0][0]=0;
for (i=0;i<=m+1;i++)
for (j=0;j<3;j++)
for (k=0;k<3;k++)
{
if (dp[i][j][k]<0) continue;
lim=cnt[i+1]-j-k;
for (t=0;t<3 && t<=lim;t++)
dp[i+1][k][t]=max(dp[i+1][k][t],dp[i][j][k]+(lim-t)/3+t);
}
printf("%d
",dp[m+1][0][0]);
return 0;
}