#include<iostream>
using namespace std;
int main()
{
int N,M,a;
while(cin >> N >> M){
int big[20] = {0};
int S = 0;
for(int i = 0; i < N; i++){
int a = 0;
for(int j = 0; j < M; j++){
cin >> a ;
if(a > big[i]){
big[i] = a;
}
}
S = S + big[i];
}
cout << S << endl;
int w = 0;
for(int i = 0; i < N; i++){
if(S % big[i] ==0){
cout << big[i] << " ";
w = 1;
}
}
if(w == 0){
cout << "-1";
}
cout << endl;
}
return 0;
}