#include<queue>
#include<cstdio>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

const int INF=1<<29;
const int dx[]={1,0,-1,-1,0,1},dy[]={0,-1,-1,0,1,1};	// truss

struct P{ int x,y; P(int Y,int X):x(X),y(Y){} };

int n,node[10][10];

bool inrange(int i,int j){ return (0<=i && i<n && 0<=j && j<=i); }

int calcScore(int c){
	int score=0;

	bool visited[10][10]={};
	rep(i,n)rep(j,i+1)if(node[i][j]!=0 && !visited[i][j]){
		int num=node[i][j];
		visited[i][j]=true;

		int cnt=0;
		bool fill=true;
		queue<P> qu;	qu.push(P(i,j));
		while(!qu.empty()){
			P a=qu.front();	qu.pop();
			rep(i,6){
				int xx=a.x+dx[i],yy=a.y+dy[i];
				if(inrange(yy,xx) && node[yy][xx]==0){ fill=false; break; }
			}
			cnt++;

			rep(i,6){
				int xx=a.x+dx[i],yy=a.y+dy[i];
				if(inrange(yy,xx) && !visited[yy][xx] && node[yy][xx]==num){
					qu.push(P(yy,xx));
					visited[yy][xx]=true;
				}
			}
		}

		if(fill){
			if(num==c)	score-=cnt;
			else		score+=cnt;
		}
	}

	return score;
}

int main(){
	for(int c;scanf("%d%d",&n,&c),n;){
		rep(i,n)rep(j,i+1)	scanf("%d",node[i]+j);

		int ans=-INF;
		rep(i,n)rep(j,i+1)if(node[i][j]==0){
			node[i][j]=c;
			ans=max(ans,calcScore(c));
			node[i][j]=0;
		}

		printf("%d\n",ans);
	}

	return 0;
}