#include<iostream>
#include<vector>

using namespace std;

int N,C;
vector<vector<int> > V;
int dx[] = {-1,0,-1,1,0,1};
int dy[] = {-1,-1,0,0,1,1}; 

void print(const vector<vector<int> >& v){
  for(int i = 0; i < (int)v.size(); i++){
    for(int j = 0; j < (int)v[i].size(); j++) cout << v[i][j] << " ";
    cout << endl;
  }
}

void input(){
  V.resize(N,vector<int>());
  for(int i = 0; i < N; i++){
    V[i].resize(i+1);
    for(int j = 0; j < (int)V[i].size(); j++) cin >> V[i][j];
  }
}

void dfs(int x, int y, int col, vector< vector<int> >& v){

  if(v[y][x] <= 0) return;
   v[y][x] = -1;
  for(int i = 0; i < 6; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(0>ny || ny>=(int)v.size()) continue;
    if(0>nx || nx>=(int)v[ny].size()) continue;
    if(v[ny][nx] == col) dfs(nx,ny,col,v);
  }
}

int count(vector< vector<int> > v, int col){

  for(int i = 0; i < (int)v.size(); i++)
    for(int j = 0; j < (int)v[i].size(); j++){
      if(v[i][j] != 0) continue;
      for(int k = 0; k < 6; k++){
	int nx = j+dx[k];
	int ny = i+dy[k];
	if(0>ny || ny>=(int)v.size()) continue;
	if(0>nx || nx>=(int)v[ny].size()) continue;
	if(v[ny][nx] <= 0) continue;
	dfs(nx,ny,v[ny][nx],v);
      }
    }

  int res = 0;
  for(int i = 0; i < (int)v.size(); i++)
    for(int j = 0; j < (int)v[i].size(); j++){
      if(v[i][j] <= 0) continue;
      res += (v[i][j]==col?-1:1);
    }
  return res;
}

void solve(){
  int ans = -(1<<25);
  for(int i = 0; i < (int)V.size(); i++)
    for(int j = 0; j < (int)V[i].size(); j++){
      if(V[i][j] != 0) continue;
	V[i][j] = C;
	ans = max(ans,count(V,C));
	V[i][j] = 0;	
    }
  cout << ans << endl;
}

int main(){
  while(cin >> N >> C && (N|C)){
    input();
    solve();
  }
}