#include <bits/stdc++.h>
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define pb push_back
using namespace std;
int C[1000005], N, M;
unordered_map<int,int> Cnt;
vector<int> IDS[1000005];
int main()
{
cin >> N >> M;
int low = 1;
f(i,1,N)
{
f(j,1,M)
{
int id;
scanf("%d", &id);
int curr = Cnt[id];
Cnt[id] = curr+1;
C[curr]--, C[curr+1]++;
IDS[curr+1].pb(id);
low = min(low, curr+1);
}
while(!C[low]) low++;
while(Cnt[IDS[low].back()] != low) IDS[low].pop_back();
printf("%d\n", IDS[low].back());
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZihpLGEsYikgZm9yKGludCBpID0gKGEpOyBpIDw9IChiKTsgaSsrKQojZGVmaW5lIHBiIHB1c2hfYmFjawoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBDWzEwMDAwMDVdLCBOLCBNOwp1bm9yZGVyZWRfbWFwPGludCxpbnQ+IENudDsKdmVjdG9yPGludD4gSURTWzEwMDAwMDVdOwoKaW50IG1haW4oKQp7CiAgICBjaW4gPj4gTiA+PiBNOwoKICAgIGludCBsb3cgPSAxOwoKICAgIGYoaSwxLE4pCiAgICB7CiAgICAgICAgZihqLDEsTSkKICAgICAgICB7CiAgICAgICAgICAgIGludCBpZDsKICAgICAgICAgICAgc2NhbmYoIiVkIiwgJmlkKTsKICAgICAgICAgICAgaW50IGN1cnIgPSBDbnRbaWRdOwogICAgICAgICAgICBDbnRbaWRdID0gY3VycisxOwogICAgICAgICAgICBDW2N1cnJdLS0sIENbY3VycisxXSsrOwogICAgICAgICAgICBJRFNbY3VycisxXS5wYihpZCk7CiAgICAgICAgICAgIGxvdyA9IG1pbihsb3csIGN1cnIrMSk7CiAgICAgICAgfQoKICAgICAgICB3aGlsZSghQ1tsb3ddKSBsb3crKzsKICAgICAgICB3aGlsZShDbnRbSURTW2xvd10uYmFjaygpXSAhPSBsb3cpIElEU1tsb3ddLnBvcF9iYWNrKCk7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgSURTW2xvd10uYmFjaygpKTsKICAgIH0KfQo=