#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int preferences[305][305];
int indices[305];
bool included[305];
int sport_count[305];

bool check(int n, int m, int k)
{
    for0(i,n) 
        indices[i] = 0;
    for (int i=1; i<=m; i++) {
        included[i] = true;
        sport_count[i] = 0;
    }
    for0(i,n) {
        sport_count[preferences[i][0]]++;
    }
    
    int num_sports = m;
    while (num_sports--) {
        //printa(sport_count,m+1);
        //find sport with max count 
        int max_cnt = 0, sport=0;
        for (int i=1; i<=m; i++) {
            if (included[i] && sport_count[i] > max_cnt) {
                max_cnt = sport_count[i];
                sport = i;
            }
        }
        //prl(sport) prl(max_cnt)
        if (max_cnt <= k)
            return true;
        
        //remove sport with max count 
        included[sport] = false;
        for0(i,n) {
            if (preferences[i][indices[i]] == sport) {
                while (indices[i] < m && !included[preferences[i][indices[i]]]){
                    indices[i]++;
                }
                if (indices[i] == m)
                    return false;
                sport_count[preferences[i][indices[i]]]++;
            }
        }
        //printa(indices,n);
        //nl
    }
    
    return false;
}

int32_t main()
{
    #ifdef DEBUG
    freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n,m;
    read(n); read(m);
    for0(i,n) {
        for0(j,m) {
            read(preferences[i][j]);
        }
    }
    
    int low=1, high=n;
    while (low < high) {
        int mid = (low+high)/2;
        if (check(n,m,mid)) {
            high = mid;
        }
        else {
            low = mid+1;
        }
    }
    pr(low) pr(high) nl
    cout<<high<<endl;
    return 0;
}


Measured memory_bytes: 1024