#include<bits/stdc++.h>
using namespace std;
int n,m,a[250][250],x;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	cin>>a[i][j];
  }
}
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
		x=a[i][j];
   // if(x<10) cout<<x<<endl; 
  /// if(x>=10&&x<=99&&x%11==0) cout<<x<<endl;
  //  if(x>=100&&x<=999&&x%10==x/100%10)cout<<x<<endl;
  //  if(x>=1000&&x<=9999&&x%10==x/1000&&x/100%10==x/10%10)cout<<x<<endl;
  while(a[i][j]!=0){
  	s=s*10+a[i][j]%10;
  	a[i][j]=a[i][j]/10;
  }
  if(s==x) cout<<x<<endl;
  x=0;
  }
}







	return 0;
}

/**************************************************************
	Problem: 1403
	User: wangyousi
	Language: C++
	Result: Compile Error
****************************************************************/