#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<sstream>
#include<queue>
#include<set>
#include<cmath>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int mp[300+5][300+56];
int n,m;
int idx[305];
int cnt[305];
int mp2[300+5][300+5];
int pos[305][305];
int check(int x){
    memset(cnt,0,sizeof(cnt));
    for(int i = 0;i<n;i++){
        cnt[mp2[i][idx[i]]]++;
    }
    int mx = -1;
    int res ;
    for(int i = 1;i<=m;i++){
        if(mx<cnt[i]){
        mx = max(mx,cnt[i]);
        res = i;
        }
    }
    if(mx>x)
        return -res;
    return res;
}
void print()
{
    for(int i = 0 ;i<n;i++){
        for(int j = 0;j<m;j++){
            printf("%d%c",mp2[i][j],j==m-1?'\n':' ');
        }
    }
}
int ok(int x){
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            mp2[i][j] = mp[i][j];
        }
    }
    memset(idx,0,sizeof(idx));
    for(int i = 0;i<m;i++)
    {
        int res = check(x);
        //print();
        if(res>0)
            return 1;
        for(int j = 0;j<n;j++){
            mp2[j][pos[j][-res]] = 0;
        }
        for(int j  = 0;j<n;j++){
            while(mp2[j][idx[j]]==0&&idx[j]<m){
                idx[j]++;
            }
            if(idx[j]>=m)
                return 0;
        }
    }
    return 0;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i = 0;i<n;i++){
            for(int j = 0;j<m;j++){
                scanf("%d",&mp[i][j]);
                pos[i][mp[i][j]] = j;
            }
        }
        int l = 0;
        int r = n+1;
        while(r-l>1){
            int mid = (l+r)>>1;
            if(ok(mid)){
                r = mid;
            }
            else
                l =mid;
        }
        cout<<r<<endl;
    }
}
