#include<bits/stdc++.h>
using namespace std;
#define MOD (int)(1e9+7)
#define INF 123456789
#define MAX 12

int n, m;
int temp[MAX][MAX];

int hoge(int flag[MAX][MAX],int ii, int jj){
  bool f = false;
  int count = 0;

  if(flag[ii][jj] == true) return 0;
  if(temp[ii][jj] != 0) flag[ii][jj] = true;
  else return 0;

  //cout<<ii<<" "<<jj<<" "<<temp[ii][jj]<<endl;
  
  queue<pair<int,int>> Q;
  Q.push(make_pair(ii,jj));
  
  while(!Q.empty()){
    pair<int,int> p = Q.front(); Q.pop();
    int y = p.first, x = p.second;
    //cout<<"+++++"<<temp[y][x] <<" "<<temp[ii][jj]<<endl;
    if(temp[y][x] == temp[ii][jj]){
      count++;//cout<<ii<<" "<<jj<<" "<<y<<" "<<x<<" "<<temp[y][x]<<endl;
    }
    for(int i = -1; i <= 1; i++){
      for(int j = -1; j <= 1; j++){
	if(j == i*-1) continue;//cout<<ii<<" "<<jj<<" "<<ny<<" "<<nx<<" "<<temp[ny][nx]<<endl;
	//cout<<i<<" "<<j<<endl;
	int ny = y + i, nx = x + j;
	if(!(1 <= ny && ny <= n && 1 <= nx && nx <= ny))continue;
	if(flag[ny][nx] == true) continue;
	if(temp[y][x] == temp[ny][nx]){//cout<<ii<<" "<<jj<<" "<<ny<<" "<<nx<<" "<<temp[ny][nx]<<endl;
	  flag[ny][nx] = true;
	  Q.push(make_pair(ny,nx));
	} else if(temp[ny][nx] == 0){
	  //cout<<ii<<" "<<jj<<" "<<ny<<" "<<nx<<" 0"<<endl;
	  f = true;
	}
      }
    }
  }
  //cout<<"count "<<ii<<" "<<jj<<" "<<count<<endl; 
  if(temp[ii][jj] == m){
    if(!f)return count*-1;
  }else {
    if(!f)return count;
  }
  return 0;
}




int huga(){
  int flag[MAX][MAX] = {};
  int count = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= i; j++){
      count += hoge(flag,i,j);
    }
  }
  return count;
}

int main(){
  
  while(true){
    int ans = INF*-1;
    vector<pair<int,int>> ve;
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= i; j++){
	cin>>temp[i][j];
	if(temp[i][j] == 0) ve.push_back(make_pair(i,j));
      }
    }
    for(pair<int,int> y : ve){
      temp[y.first][y.second] = m;
      ans = max(huga(),ans);
      temp[y.first][y.second] = 0;
    }

    cout<<ans<<endl;
  }

  return 0;
}

