#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
int dy[6] = {0, 1, 1, 0, -1, -1};
int dx[6] = {1, 0, -1, -1, 0, 1};

int dfs(int y, int x, int c, bool &z, vector<vector<int> > &s){
    if(s[y][x] == 0) z = true;
    if(s[y][x] != c) return 0;
    s[y][x] = -1;

    int ret = 1;
    for(int i=0; i<6; i++){
        ret += dfs(y+dy[i], x+dx[i], c, z, s);
    }
    return ret;
}

int solve(int y, int x, int c, vector<vector<int> > s){
    s[y][x] = c;
    int n = s.size()-2;
    int ret = 0;
    for(int i=n; i>0; i--){
        for(int j=1; j<=n-i+1; j++){
            if(s[i][j] <= 0) continue;
            bool z = false;
            int sign = (s[i][j] == c)? -1: 1;
            int score = dfs(i, j, s[i][j], z, s);
            if(!z) ret += sign *score;
        }
    }
    return ret;
}

int main(){
    while(1){
        int n,c;
        cin >> n >> c;
        if(n==0) break;

        vector<vector<int> > s(n+2, vector<int>(n+2, -1));
        for(int i=n; i>0; i--){
            for(int j=1; j<=n-i+1; j++){
                cin >> s[i][j];
            }
        }

        int ans = -inf;
        for(int i=n; i>0; i--){
            for(int j=1; j<=n-i+1; j++){
                if(s[i][j] == 0){
                    int score = solve(i, j, c, s);
                    ans = max(ans, score);
                }   
            }
        }
        cout << ans << endl;
    }
    return 0;
}

