#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int board[10][10];
int tmp[10][10];
int n, c;

int dx[] = {1,0,-1,-1,0,1};
int dy[] = {0,-1,-1,0,1,1};

bool flag;
int dfs(int y, int x) {
//   printf("%d,%d\n", y,x);
  int m = tmp[y][x];
//  cout << m << endl;
  tmp[y][x] = -1;
  int res = 1;
  REP(k,6) {
    int yy = y+dy[k];
    int xx = x+dx[k];

    if (yy<0||yy>=n || xx<0||xx>yy) continue;
    if (tmp[yy][xx] == m) {
      res += dfs(yy,xx);
    } else if (tmp[yy][xx] == 0)
      flag = 0;
  }
  return res;
}

int score(int y, int x) {
  int res = 0;
  memcpy(tmp, board, sizeof(board));
  tmp[y][x] = c;      
  REP(i,n) {
    REP(j, i+1) {
      if (tmp[i][j] >= 1) {
        flag = 1;
        int hoge = (tmp[i][j]==c)? -1 : 1;
        hoge *= dfs(i, j);
//        cout << hoge << endl;
        if (flag)
          res += hoge;
//        cout << "res = " << res << endl;
      }
    }
  }
  return res;
}

int main() {
  while(cin >> n >> c, n||c) {
    REP(i,n)
      REP(j, i+1) {
        cin >> board[i][j];
    }
    int res = -INF;
    REP(i,n)
      REP(j, i+1)
      if (board[i][j] == 0)
        res = max(res, score(i,j));
    cout << res << endl;
  }
}