""" 横の和は当然Mである必要がある 縦の和もM """ import sys from sys import stdin N,M = map(int,stdin.readline().split()) A = [ list(map(int,stdin.readline().split())) for i in range(N) ] flag = True for i in range(N): s = 0 for j in range(N): s += A[i][j] if s != M: flag = False for j in range(N): s = 0 for i in range(N): s += A[i][j] if s != M: flag = False if flag == False: print (12912091) else: print (-1)