n = list(map(int,input().split()))
#n(0)為N,n(1)為N
max_data = []
for _ in range(n[0]):
max_data.append(max(list(map(int,input().split()))))
#直接把輸入的串列取最大值放入-->「max_data]
answer = sum(max_data)
print(answer)
#輸入第一行的數字
answer_data = list(filter(lambda x:answer%x == 0,max_data))
#用過濾器把符合條件的值留下
if len(answer_data) == 0:
print('-1')
#如果是空串列(沒有符合的數字)就輸出'-1'
else:
for i in answer_data[0:-1]:
print(i,end=' ')
print(answer_data[-1])