column, row = map(int,input().split(' '))
x = []
y = []
sum = 0
count = 0
for i in range(column):
x.append(list(map(int,input().split(' '))))
for i in x:
sum += max(i)
print(sum)
for i in range(column):
for j in range(row):
if sum % x[i][j] == 0:
print(x[i][j])
count += 1
if count == 0:
print('-1')