#include<bits/stdc++.h>
using namespace std;
#define IOS cin.tie(nullptr)->sync_with_stdio(0),cin.exceptions(cin.failbit);
#define lb(x) (x)&-(x)
#define all(x) (x).begin(),(x).end()
#define ll long long
constexpr int maxN=3e2+5;
int n,m,val[maxN][maxN],ptr[maxN];
bitset<maxN> vis;
vector<int> adj[maxN],adj2[maxN];
inline bool chk(int guess){
fill(ptr,ptr+n+1,0);
vis.reset();
for(int i = 1;i<=m;i++)adj[i].clear(),adj2[i].clear();
for(int i = 1;i<=n;i++)adj[val[i][0]].emplace_back(i);
for(int flag = 1;flag;){
flag = 0;
for(int j = 1;j<=m;j++)if(adj[j].size()>guess){
flag = 1;
vis[j]=1;
for(int k:adj[j]){
while(ptr[k]<m&&vis[val[k][ptr[k]]])ptr[k]++;
if(ptr[k]==m)return 0;
adj[val[k][ptr[k]]].emplace_back(k);
}
adj[j].clear();
}
}
return 1;
}
int main(){
IOS
cin>>n>>m;
for(int i = 1;i<=n;i++)for(int j = 0;j<m;j++)cin>>val[i][j];
for(int i = 1;i<=n;i++)if(chk(i))return cout<<i<<'\n',0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBJT1MgY2luLnRpZShudWxscHRyKS0+c3luY193aXRoX3N0ZGlvKDApLGNpbi5leGNlcHRpb25zKGNpbi5mYWlsYml0KTsKI2RlZmluZSBsYih4KSAoeCkmLSh4KQojZGVmaW5lIGFsbCh4KSAoeCkuYmVnaW4oKSwoeCkuZW5kKCkKI2RlZmluZSBsbCBsb25nIGxvbmcKCmNvbnN0ZXhwciBpbnQgbWF4Tj0zZTIrNTsKCmludCBuLG0sdmFsW21heE5dW21heE5dLHB0clttYXhOXTsKCmJpdHNldDxtYXhOPiB2aXM7Cgp2ZWN0b3I8aW50PiBhZGpbbWF4Tl0sYWRqMlttYXhOXTsKCmlubGluZSBib29sIGNoayhpbnQgZ3Vlc3MpewogICAgZmlsbChwdHIscHRyK24rMSwwKTsKICAgIHZpcy5yZXNldCgpOwogICAgZm9yKGludCBpID0gMTtpPD1tO2krKylhZGpbaV0uY2xlYXIoKSxhZGoyW2ldLmNsZWFyKCk7CiAgICBmb3IoaW50IGkgPSAxO2k8PW47aSsrKWFkalt2YWxbaV1bMF1dLmVtcGxhY2VfYmFjayhpKTsKICAgIGZvcihpbnQgZmxhZyA9IDE7ZmxhZzspewogICAgICAgIGZsYWcgPSAwOwogICAgICAgIGZvcihpbnQgaiA9IDE7ajw9bTtqKyspaWYoYWRqW2pdLnNpemUoKT5ndWVzcyl7CiAgICAgICAgICAgIGZsYWcgPSAxOwogICAgICAgICAgICB2aXNbal09MTsKICAgICAgICAgICAgZm9yKGludCBrOmFkaltqXSl7CiAgICAgICAgICAgICAgICB3aGlsZShwdHJba108bSYmdmlzW3ZhbFtrXVtwdHJba11dXSlwdHJba10rKzsKICAgICAgICAgICAgICAgIGlmKHB0cltrXT09bSlyZXR1cm4gMDsKICAgICAgICAgICAgICAgIGFkalt2YWxba11bcHRyW2tdXV0uZW1wbGFjZV9iYWNrKGspOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGFkaltqXS5jbGVhcigpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAxOwp9CgppbnQgbWFpbigpewogICAgSU9TCiAgICBjaW4+Pm4+Pm07CiAgICBmb3IoaW50IGkgPSAxO2k8PW47aSsrKWZvcihpbnQgaiA9IDA7ajxtO2orKyljaW4+PnZhbFtpXVtqXTsKICAgIGZvcihpbnQgaSA9IDE7aTw9bjtpKyspaWYoY2hrKGkpKXJldHVybiBjb3V0PDxpPDwnXG4nLDA7Cn0=