#include <bits/stdc++.h>
#define lli long long int
using namespace std;
typedef multimap<int,int>::iterator it;
multimap<int , int> score;
map<int , it> num;
void increase(int x)
{
it score_it;
map<int , it>::iterator num_it = num.find(x);
if ( num_it == num.end() )
{
num[x] = score.insert( make_pair( 1 , x ) );
}
else
{
score_it = (num_it->second);
int cnt = score_it->first + 1;
score.erase( score_it );
num_it->second = score.insert( make_pair( cnt , x ) );
}
}
int getMin()
{
return score.begin()->second;
}
int main()
{
ios_base::sync_with_stdio(false);
int n , m;
cin>>n>>m;
for (int i=0 ; i<n ; i++)
{
for (int j=0 ; j<m ; j++)
{
int x; cin>>x;
increase(x);
}
cout<<getMin()<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGxpIGxvbmcgbG9uZyBpbnQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbXVsdGltYXA8aW50LGludD46Oml0ZXJhdG9yIGl0OwptdWx0aW1hcDxpbnQgLCBpbnQ+IHNjb3JlOwptYXA8aW50ICwgaXQ+IG51bTsKCnZvaWQgaW5jcmVhc2UoaW50IHgpCnsKCWl0IHNjb3JlX2l0OwoJbWFwPGludCAsIGl0Pjo6aXRlcmF0b3IgbnVtX2l0ID0gbnVtLmZpbmQoeCk7CglpZiAoIG51bV9pdCA9PSBudW0uZW5kKCkgKQoJewoJCW51bVt4XSA9IHNjb3JlLmluc2VydCggbWFrZV9wYWlyKCAxICwgeCApICk7Cgl9CgllbHNlCgl7CgkJc2NvcmVfaXQgPSAobnVtX2l0LT5zZWNvbmQpOwoJCWludCBjbnQgPSBzY29yZV9pdC0+Zmlyc3QgKyAxOwoJCXNjb3JlLmVyYXNlKCBzY29yZV9pdCApOwoJCW51bV9pdC0+c2Vjb25kID0gc2NvcmUuaW5zZXJ0KCBtYWtlX3BhaXIoIGNudCAsIHggKSApOwoJfQp9CgppbnQgZ2V0TWluKCkKewoJcmV0dXJuIHNjb3JlLmJlZ2luKC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