#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

int N = 10, C;

int calc(vector<vector<int>> &v)
{
    int res = 0;
    vector<vector<bool>> check(N, vector<bool>(2 * N - 1, true));
    /*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 2 * N - 1; j++)
        {
            cout << " " << v[i][j];
        }
        cout << endl;
    }*/
    queue<P> q;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 2 * N - 1; j++)
        {
            if (v[i][j] == -1)
            {
                check[i][j] = false;
                continue;
            }
            if (v[i][j] == 0)
            {
                check[i][j] = false;
                continue;
            }
            for (int k = 0; k < 6; k++)
            {
                int nx = i + dx[k], ny = j + dy[k];
                if (nx < 0 || N <= nx || ny < 0 || 2 * N - 1 <= ny)
                    continue;
                if (v[nx][ny] != 0)
                    continue;
                q.push(P(i, j));
                check[i][j] = false;
                break;
            }
        }
    }
    while (!q.empty())
    {
        P p = q.front();
        q.pop();
        for (int i = 0; i < 6; i++)
        {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (nx < 0 || N <= nx || ny < 0 || 2 * N - 1 <= ny)
                continue;
            if (!check[nx][ny])
                continue;
            if (v[p.first][p.second] != v[nx][ny])
                continue;
            q.push(P(nx, ny));
            check[nx][ny] = false;
        }
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 2 * N - 1; j++)
        {
            if (!check[i][j])
                continue;
            if (v[i][j] == C)
            {
                res--;
                // cout << "- " << i << " " << j << endl;
            }
            else
            {
                // cout << "+ " << i << " " << j << endl;
                res++;
            }
        }
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (cin >> N >> C, N)
    {
        vector<vector<int>> v(N, vector<int>(2 * N - 1, -1));
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                int s;
                cin >> s;
                v[i][N - 1 - i + 2 * j] = s;
            }
        }
        int res = -INF;
        vector<vector<int>> tmp(N, vector<int>(2 * N - 1, -1));
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 2 * N - 1; j++)
            {
                if (v[i][j] == 0)
                {
                    for (int k = 0; k < N; k++)
                    {
                        for (int l = 0; l < 2 * N - 1; l++)
                        {
                            tmp[k][l] = v[k][l];
                        }
                    }
                    // cout << i << " " << j << endl;
                    tmp[i][j] = C;
                    res = max(res, calc(tmp));
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3136