//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
ll n,m,a[400][400],mn,mx,b[400],d[400],x,y,re;
vl v;
bool vis[400];
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mon(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    rep(i,1,n)
    {
        b[i]=1;
        rep(j,1,m)
        {
            cin>>a[i][j];
        }
    }
    rep(i,1,m)
    {
        v.pb(i);
    }
    rep(i,1,n)d[a[i][b[i]]]++;
    re=1e18;
    rrep(i,m,2)
    {
        //cout<<mn<<endl;
        mx=0;
        mn=1e18;
        FR(j,0,v.SZ)
        {
            if(d[v[j]]>mx)
            {
                mx=d[v[j]];
                x=j;
                //cout<<j<<endl;
            }
        }
        y=v[x];
        //cout<<y<<endl<<endl;
        vis[y]=true;
        v.erase(v.begin()+x);
        mn=min(mn,mx);
        re=min(mn,re);
        rep(i,1,n)
        {
            if(vis[a[i][b[i]]]){
            while(vis[a[i][b[i]]]&&b[i]<=m)
            {
                b[i]++;
            }
            if(b[i]<=m)d[a[i][b[i]]]++;
            //cout<<a[i][b[i]]<<endl;
            }
        }
        //cout<<endl;
    }
        mx=0;
        mn=1e18;
        FR(j,0,v.SZ)
        {
            if(d[v[j]]>mx)
            {
                mx=d[v[j]];
                x=j;
                //cout<<j<<endl;
            }
        }
        re=min(re,mx);
    cout<<re;
    return 0;
}


Measured memory_bytes: 1280