#include <bits/stdc++.h>
using namespace std;
bool huiwen(int n){
bool r = true;
int t = n,x = 0;
while(n != 0){
x = x * 10 + n % 10;
n = n / 10;
}
if(x != t){
r = false;
}
return r;
}
int main(){
int a[200][200];
int i,j,n,m;
cin >> n >> m;
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
cin >> a[i][j];
}
}
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
if(huiwen(a[i][j]) == true){
cout << a[i][j] << endl;
}
}
}
}