#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

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

int bfs(vector<vector<int>> const& board, vector<vector<bool>>& visited, int y, int x) {
    int id = board[y][x];
    bool f = false;
    int res = 1;
    queue<P> que;
    que.push(P{y, x});
    visited[y][x] = true;
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        for(int i=0; i<6; ++i) {
            int ny = p.first + dy[i],
                nx = p.second + dx[i];
            if(ny < 0 || board.size() <= ny || nx < 0 || ny < nx || visited[ny][nx]) {
                continue;
            }
            if(board[ny][nx] != id) {
                f |= board[ny][nx] == 0;
                continue;
            }
            visited[ny][nx] = true;
            res++;
            que.push(P{ny, nx});
        }
    }
    if(f) {
        return 0;
    } else {
        return res;
    }
}
 
int main() {
    int N, C;
    while(cin >> N >> C, N) {
        vector<vector<int>> board(N, vector<int>(N, -1));
        for(int i=1; i<=N; ++i) {
            for(int j=0; j<i; ++j) {
                cin >> board[i-1][j];
            }
        }
        int res = -1e9;
        for(int i=1; i<=N; ++i) {
            for(int j=0; j<i; ++j) {
                if(board[i-1][j] == 0) {
                    vector<vector<bool>> visited(N, vector<bool>(N));
                    board[i-1][j] = C;
                    int t = -bfs(board, visited, i-1, j);
                    for(int k=0; k<6; ++k) {
                        int ny = i-1 + dy[k],
                            nx = j + dx[k];
                        if(ny < 0 || board.size() <= ny || nx < 0 || ny < nx || visited[ny][nx]) {
                            continue;
                        }
                        if(board[ny][nx] == 0) {
                            continue;
                        }
                        t += bfs(board, visited, ny, nx);
                    }
                    res = max(res, t);
                    board[i-1][j] = 0;
                }
            }
        }
        cout << res << endl;
    }
}
