#include<stdio.h>
#include<algorithm>
using namespace std;
int c[20][20];
int UF[1100];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;
	UF[a]+=UF[b];UF[b]=a;
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			for(int j=0;j<=i;j++)scanf("%d",&c[i][j]);
		}
		int ret=-99999999;
		for(int i=0;i<a;i++){
			for(int j=0;j<=i;j++){
				if(c[i][j])continue;
				c[i][j]=b;
				for(int k=0;k<=a*a;k++)UF[k]=-1;
				int z=a*a;
				for(int k=0;k<a;k++){
					for(int l=0;l<=k;l++){
						if(c[k][l]==0)UNION(z,k*a+l);
						if(l<k&&!(c[k][l]&&c[k][l+1]&&c[k][l]!=c[k][l+1]))UNION(k*a+l,k*a+l+1);
						if(k<a-1&&!(c[k][l]&&c[k+1][l]&&c[k][l]!=c[k+1][l]))UNION(k*a+l,k*a+l+a);
						if(k<a-1&&!(c[k][l]&&c[k+1][l+1]&&c[k][l]!=c[k+1][l+1]))UNION(k*a+l,k*a+l+a+1);
					}
				}
				int tmp=0;
				for(int k=0;k<a;k++)for(int l=0;l<=k;l++){	
					if(!c[k][l])continue;
					if(FIND(z)!=FIND(k*a+l)){
						if(c[k][l]==b)tmp--;
						else tmp++;
					}
				}
				ret=max(ret,tmp);
				c[i][j]=0;
			}
		}
		printf("%d\n",ret);
	}
}