### constant

INF = 1 << 30
DXYS = [[1, 0], [0, -1], [-1, -1], [-1, 0], [0, 1], [1, 1]]

### subroutines

def gain(n, flds, c)
  used = n.times.map{|y| (y + 1).times.map{false}}
  gain = 0
  
  for y in (0...n)
    for x in (0..y)
      id = flds[y][x]
      next if used[y][x] || id == 0

      emp = false
      nst = 1
      used[y][x] = true
      q = [[x, y]]

      while ! q.empty?
        ux, uy = q.shift

        DXYS.each do |dx, dy|
          vx = ux + dx
          vy = uy + dy
          if vx >= 0 && vx <= vy && vy >= 0 && vy < n
            vid = flds[vy][vx]
            v = [vx, vy]
            if vid == 0
              emp = true
            elsif vid == id && ! used[vy][vx]
              nst += 1
              used[vy][vx] = true
              q << v
            end
          end
        end
      end

      if ! emp
        gain += (id == c) ? -nst : nst
      end
    end
  end

  gain
end

### main

loop do
  n, c = gets.split.map(&:to_i)
  break if (n | c) == 0

  flds = n.times.map{gets.split.map(&:to_i)}
  #p flds

  max_g = -INF

  for y in (0...n)
    for x in (0..y)
      if flds[y][x] == 0
        flds[y][x] = c
        g = gain(n, flds, c)
        max_g = g if max_g < g
        flds[y][x] = 0
      end
    end
  end

  puts max_g
end