#include <bits/stdc++.h>

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int n,m;
int ans=INT_MAX;
int a[500][500];
void solve(int num,set<int>&s)
{
    if(num==m)
    {
        return ;
    }
    vector<int>v(m+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s.count(a[i][j]))
                continue;
            else
            {
                v[a[i][j]]++;
                break;
            }
        }
    }
    int val=maxe(v.begin(),v.end());
    ans=min(ans,val);
    for(int i=1;i<=m;i++)
    {
        if(v[i]==val)
        {
            s.insert(i);
            solve(num+1,s);
            return;
        }
    }
}
int32_t main() {
    nitin;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    set<int>s;
    solve(0,s);
    cout<<ans<<endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int read() {
    char cc = getchar(); int cn = 0, flus = 1;
    while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }
    while(cc >= '0' && cc <= '9')  cn = cn * 10 + cc - '0', cc = getchar();
    return cn * flus;
}
const int N = 1000 + 5 ; 
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
int n, m, book[N], w[N][N], vis[N], can[N];   
bool check( int x ) {
    memset( book, 0, sizeof(book) ), memset( can, 0, sizeof(can) ) ;
    int flag ; rep( i, 1, n ) vis[i] = 1, ++ book[w[i][vis[i]]] ; 
    rep( i, 1, m ) {
        flag = 1 ; 
        rep( j, 1, n ) {
            int u = w[j][vis[j]] ; 
            if( book[u] > x ) {
                can[u] = 1; flag = 0 ; 
                while( vis[j] <= n && can[w[j][vis[j]]] ) ++ vis[j] ; 
                if( vis[j] > n ) return 0; 
                ++ book[w[j][vis[j]]] ; 
            }
        }
        if( flag ) return 1; 
    }
    return 0 ; 
}
signed main()
{
    n = read(), m = read() ; 
    rep( i, 1, n ) rep( j, 1, m ) w[i][j] = read() ; 
    int l = 1, r = n, ans = 0, mid ; 
    while( l <= r ) {
        mid = ( l + r ) >> 1 ; 
        if( check(mid) ) ans = mid, r = mid - 1 ; 
        else l = mid + 1 ; 
    }
    printf("%d\n", ans ) ; 
    return 0;
}