#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void solve() {
    while (true) {
        int n, c;
        cin >> n >> c;
        if (n == 0) return;
        vector<vector<int>> base;
        REP(i, n) {
            base.push_back(vector<int>{});
            REP(q, i + 1) {
                int a;
                cin >> a;
                base.back().push_back(a);
            }
        }
        int now_ans = -1e9;
        REP(i, n) {
            REP(q, base[i].size()) {
                if (base[i][q] != 0) continue;
                base[i][q] = c;
                vector<vector<int>> expected = base;
                int ans = 0;
                queue<pair<int, int>> next;
                REP(j, n) {
                    REP(t, j + 1) {
                        if (expected[j][t] == 0) continue;
                        int target = expected[j][t];
                        expected[j][t] = 0;
                        next.push(mp(j, t));
                        int cnt = 0;
                        int conn = 0;
                        while (next.empty() == false) {
                            cnt++;
                            pair<int, int> now = next.front();
                            next.pop();
                           // cout << now.first << " " << now.second << endl;
                            int dx[6] = { -1,0,1,1,0,-1 };
                            int dy[6] = { -1,-1,0,1,1,0 };
                            REP(t, 6) {
                                int x = dx[t] + now.first;
                                int y = dy[t] + now.second;
                                if (x >= 0 && x < n && y >= 0 && y < x + 1) {
                                    if (expected[x][y] == target) {
                                        expected[x][y] = 0;
                                        next.push(mp(x, y));
                                    }
                                    else if (base[x][y] == 0) {
                                        conn = 1;
                                    }
                                }
                            }
                        }
                        if (conn == 0) {
                            if (target == c) {
                                cnt *= -1;
                            }
                            ans += cnt;
                        }
                    }
                }
                now_ans = max(now_ans, ans);
                base[i][q] = 0;
            }
        }
        cout << now_ans << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}



Measured memory_bytes: 3120