#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,c;
int t[10][10];
bool vis[10][10],flag;
int dy[] = {0,1,1,0,-1,-1}, dx[] = {1,1,0,-1,-1,0};

int dfs(int y,int x,int col){
  if(vis[y][x])return 0;
  if(t[y][x] != col){
    if(t[y][x] == 0)flag = true;
    return 0;
  }
  vis[y][x] = true;

  int res = 1;
  rep(i,6){
    int ty = y+dy[i], tx = x+dx[i];
    if(ty<0 || tx<0 || ty>=n || tx>ty)continue;
    res += dfs(ty,tx,col);
  }
  return res;
}

int solve(){
  int res = 0;
  rep(i,n)rep(j,i+1)vis[i][j] = false;

  int cnt = 0;
  rep(i,n)rep(j,i+1){
    if(!vis[i][j] && t[i][j]){
      cnt++;
      flag = false;
      int tmp = dfs(i,j,t[i][j]);
      if(!flag){
	if(t[i][j] == c)res -= tmp;
	else res += tmp;
      }
    }
  }
  return res;
}

int main(){
  while(cin >> n >> c,n||c){
    bool f = false;
    rep(i,n)rep(j,i+1){
      cin >> t[i][j];
      if(!t[i][j])f = true;
    }

    if(!f){
      cout << 0 << endl;
      continue;
    }

    int ans = -100000;
    rep(i,n)rep(j,i+1){
      if(!t[i][j]){
	t[i][j] = c;
	ans = max(ans,solve());
	t[i][j] = 0;
      }
    }

    cout << ans << endl;
  }
}