stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define N 305

using namespace std;

inline int rd() {

    int x=0,f=1;char ch=getchar();

    while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}

    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}

    return x*f;

}

int n,m,a[N][N],vis[N],cnt[N];

int main() {

    n = rd(), m = rd();

    for (int i=1;i<=n;i++)

        for (int j=1;j<=m;j++) a[i][j] = rd();

    for (int i=1;i<=m;i++) vis[i] = 1;

    int ans = n;

    for (int _=1;_<=m;_++) {

        memset(cnt,0,sizeof(cnt));

        for (int i=1;i<=n;i++)

            for (int j=1;j<=m;j++)

                if (vis[ a[i][j] ]) {

                    cnt[ a[i][j] ]++;

                    break;

                }

        int mx = 0, id = 0;

        for (int i=1;i<=m;i++)

            if (cnt[i] >= mx)

                mx = cnt[i], id = i;

        ans = min(ans, mx);

        vis[id] = 0;

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2111134113131925x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;



template<typename T>

void input(T &x) {

	x=0; T a=1;

	register char c=getchar();

	for(;c<48||c>57;c=getchar())

		if(c==45) a=-1;

	for(;c>=48&&c<=57;c=getchar())

		x=x*10+c-48;

	x*=a;

	return;

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

		for(int i=1;i<=n;i++) cnt[i]=1;

		while(1) {

			memset(sum,0,sizeof(sum));

			bool flag=true;

			for(int i=1;i<=n;i++) {

				for(;cnt[i]<=m&&go[a[i][cnt[i]]];cnt[i]++);

				if(cnt[i]>m) return false;

				if(++sum[a[i][cnt[i]]]>mid)

					go[a[i][cnt[i]]]=true,flag=false;

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;++j)

				input(a[i][j]);

		int l=1,r=n,ans;

		while(l<=r) {

			int mid=l+r>>1;

			if(Judge(mid)) ans=mid,r=mid-1;

			else l=mid+1;

		}

		printf("%d\n",ans);

		return 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <set>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int KN = 305;



int n, m, a[KN][KN], pos[KN][KN], cnt[KN];



set<pii> S[KN];



bool check(int mid) {

	for (int i = 1; i <= n; ++i) {

		S[i].clear();

		for (int j = 1; j <= m; ++j) 

			S[i].insert(make_pair(j, a[i][j]));

	}

	int idx;

	for (int k = 1; k < m; ++k) {

		bool can = true;

		memset(cnt, 0x00, sizeof cnt);

		for (int i = 1; i <= n; ++i)

			++cnt[S[i].begin()->second];

		for (int i = 1; i <= m; ++i)

			if (cnt[i] > mid)

				can = false, idx = i;

		if (can)

			return true;

		for (int i = 1; i <= n; ++i)

			S[i].erase(make_pair(pos[i][idx], idx));

	}

	return false;

}



int main() {

	ios::sync_with_stdio(false);

	cin >> n >> m;

	for (int i = 1; i <= n; ++i)

		for (int j = 1; j <= m; ++j) {

			cin >> a[i][j];

			pos[i][a[i][j]] = j;

		}

	int low = 0, high = n, ans = high;

	while (low <= high) {

		int mid = (low + high) >> 1;

		if (check(mid))

			ans = mid, high = mid - 1;

		else low = mid + 1;

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.494196502855791x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,a[305][305];

int cnt[305],vis[305],ans=1e9;

int findmax(){

	memset(cnt,0,sizeof(cnt));

	for (int i=1;i<=n;i++)

		for (int j=1;j<=m;j++)

			if (!vis[a[i][j]]){

				cnt[a[i][j]]++;

				break;

			}

	int mx=0;

	for (int i=1;i<=m;i++)

		if (cnt[i]>cnt[mx]) mx=i;

	ans=min(ans,cnt[mx]);

	return mx;

}

int main(){

	scanf("%d%d",&n,&m);

	for (int i=1;i<=n;i++)

		for (int j=1;j<=m;j++)

			scanf("%d",&a[i][j]);

	for (int i=1;i<=m;i++)

		vis[findmax()]=1;

	printf("%d\n",ans);

}

// Faster C++ solution for the same problem (measured speedup: 5.250871570306403x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<math.h>

#include<stdlib.h>

#include<bitset>

#include<map>

#include<queue>

#include<vector>

#include<set>

#include<iostream>

#include<string>

#define ll long long

#define N 305

#define For(i,x,y) for(int i=x;i<=y;i++)

#define Rep(i,x,y) for(int i=x;i>=y;i--)

#define Forn(i,x,y) for(int i=x;i<y;i++)

using namespace std;

int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,m,a[N][N],b[N],sum,l[N];

bool flag[N];

int main(){

	n=read();m=read();

	For(i,1,n) For(j,1,m) a[i][j]=read();

	For(i,1,n) b[a[i][1]]++;

	For(i,1,n) l[i]=1;

	For(i,1,m) flag[i]=1;

	For(i,1,m) sum=max(sum,b[i]);

	For(i,1,m-1){

		int mxj=0;For(j,1,m) if(b[j]>b[mxj]) mxj=j;

		flag[mxj]=0;

		For(j,1,n) if(a[j][l[j]]==mxj){

			b[a[j][l[j]]]--;

			while(!flag[a[j][l[j]]]) l[j]++;

			b[a[j][l[j]]]++;

		}

		int mx=0;

		For(j,1,m) mx=max(mx,b[j]);

		sum=min(sum,mx);

	}

	writeln(sum);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.209443428021572x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define Ll long long

using namespace std;

const int N=3e2+5;

int a[N][N],d[N];

bool ok[N];

int ans=1e9,n,m,x;

int find(){

	memset(d,0,sizeof d);

	int ma=0;

	for(int i=1;i<=n;i++)

		for(int j=1;j<=m;j++)

			if(!ok[a[i][j]]){

				d[a[i][j]]++;

				break;

			}

	for(int i=1;i<=m;i++)ma=max(ma,d[i]);

	for(int i=1;i<=m;i++)if(d[i]==ma)ok[i]=1;

	return ma;

}

int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++)

		for(int j=1;j<=m;j++)

			scanf("%d",&a[i][j]);

	while(1){

		int sum=0;

		for(int i=1;i<=m;i++)if(!ok[i])sum++;

		if(sum==0)break;

		ans=min(find(),ans);

	}

	printf("%d",ans);

}

// Faster C++ solution for the same problem (measured speedup: 5.248892355428534x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

inline void read(int &x)

{

	char c=getchar();

	x=0;

	while (c>'9'||c<'0')

		c=getchar();

	while (c>='0'&&c<='9')

	{

		x=x*10+c-'0';

		c=getchar();

	}

}

const int N=305;

int a[N][N],p[N],f[N],n,m,ans=23333333,pos,b[N];

int main()

{

	read(n);

	read(m);

	for (int i=1;i<=n;++i)

		for (int j=1;j<=m;++j)

			read(a[i][j]);

	for (int i=1;i<=n;++i)

		p[i]=1;

	for (int i=1;i<=m;++i)

	{

		memset(f,0,sizeof(f));

		for (int j=1;j<=n;++j)

		{

			while (b[a[j][p[j]]]&&p[j]<=m)

				++p[j];

			++f[a[j][p[j]]];

		}

		pos=1;

		for (int j=2;j<=m;++j)

			if (f[j]>f[pos])

				pos=j;

		b[pos]=1;

		/*for (int i=1;i<=m;++i)

			cout<<f[i]<<' ';

		cout<<'\n';*/

		ans=min(ans,f[pos]);

	}

	cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 5.240614882839731x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int n, m, temp, ans, a[305][305];



bool C(int ppl)

{

    bool choose[305]; //choose i-th sport

    memset(choose, true, sizeof(choose));



    while(true) {

        int cnt[305]; //count of i-th sport

        memset(cnt, 0, sizeof(cnt));

        bool used = true;



        for(int i=1; i<=n; i++) {

            int now = 1; //place of i-th sport that can be choose

            for(now=1; now<=m; now++) {

                if(choose[a[i][now]]) break;

            }

            if(now > m) return false;

            cnt[a[i][now]]++;

            if(cnt[a[i][now]] > ppl) {

                choose[a[i][now]] = false;

                used = false;

            }

        }

        if(used) return true;

    }

}



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;

    for(int i=1; i<=n; i++)

        for(int j=1; j<=m; j++)

            cin >> a[i][j];



    int lb=1, ub=n, mid=0;

    while(lb<=ub) {

        mid = (lb+ub)/2;

        if(C(mid)) {

            ans = mid;

            ub = mid-1;

        }

        else lb = mid+1;

    }

    cout << ans << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.372226228075243x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N=505;



int n,m;

int a[N][N],num[N];

bool vis[N];



void work()

{

    int ans=n;

	for(int _=1;_<=m;_++){

		memset(num,0,sizeof(num)); 

		for(int i=1;i<=n;i++) 

			for(int j=1;j<=m;j++)

				if(vis[a[i][j]]){num[a[i][j]]++;break;}

		int mx=0,id=0;

        for(int i=1;i<=m;i++) if(num[i]>=mx) mx=num[i],id=i;

        ans=min(ans,mx);

        vis[id]=0;

	}

	cout<<ans<<endl;

}



void init()

{

	cin>>n>>m;

	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];

	for(int i=1;i<=m;i++) vis[i]=1;

}



int main()

{

	init();

	work();

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.318504157392663x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define N 305

using namespace std;

inline int rd() {

    int x=0,f=1;char ch=getchar();

    while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}

    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}

    return x*f;

}

int n,m,a[N][N],vis[N],cnt[N];

int main() {

    n = rd(), m = rd();

    for (int i=1;i<=n;i++)

        for (int j=1;j<=m;j++) a[i][j] = rd();

    for (int i=1;i<=m;i++) vis[i] = 1;

    int ans = n;

    for (int _=1;_<=m;_++) {

        memset(cnt,0,sizeof(cnt));

        for (int i=1;i<=n;i++)

            for (int j=1;j<=m;j++)

                if (vis[ a[i][j] ]) {

                    cnt[ a[i][j] ]++;

                    break;

                }

        int mx = 0, id = 0;

        for (int i=1;i<=m;i++)

            if (cnt[i] >= mx)

                mx = cnt[i], id = i;

        ans = min(ans, mx);

        vis[id] = 0;

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.232473801682888x):
#include <stdint.h>

#include <stdio.h>



/* At most three digits. */

unsigned readUnsigned() {

    int c;

    do { c = ::getchar_unlocked(); } while (c < '0');

    unsigned result = c - '0';

    if ((c = ::getchar_unlocked()) >= '0') {

        result *= 10;

        result += c - '0';

        if ((c = ::getchar_unlocked()) >= '0') {

            result *= 10;

            result += c - '0';

        }

    }

    return result;

}



unsigned N, M;

unsigned A[304][304];



bool valid(unsigned x) {

    unsigned I[304] = {0};

    bool bad[304] = {0};

    for (unsigned sports = M;;) {

        unsigned counts[304] = {0};

        for (unsigned i = 0; i < N; ++i) {

            if (++counts[A[i][I[i]]] > x) {

                unsigned badsport = A[i][I[i]];

                bad[badsport] = true;

                if (--sports * x < N) return false;

                for (unsigned j = 0; j < N; ++j) {

                    while (bad[A[j][I[j]]]) {

                        ++I[j];

                    }

                }

                goto next;

            }

        }

        return true;

next:;

    }

    return false;

}



int main() {

    N = readUnsigned();

    M = readUnsigned();

    for (unsigned i = 0; i < N; ++i) {

        for (unsigned j = 0; j < M; ++j) {

            A[i][j] = readUnsigned() - 1;

        }

    }



    unsigned x = 0;

    for (unsigned step = M; step; step /= 2) {

        while (!valid(x + step)) x += step;

    }

    printf("%u\n", x + 1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int n,m,ans,mark[305],cnt[305],g[305][305];



int main(){

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++){

        for(int j=1;j<=m;j++)

          scanf("%d",&g[i][j]);

    }

    ans=n+1;

    for(int i=1;i<=m;i++){

        memset(cnt,0,sizeof(cnt));

        for(int j=1;j<=n;j++){

            int k=1;

            while(mark[g[j][k]]==1) k++;

            cnt[g[j][k]]++;

        }

        int mx=0;

        for(int j=1;j<=m;j++)

          if(cnt[j]>cnt[mx]) mx=j;

        ans=min(ans,cnt[mx]);

        mark[mx]=1;

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.126863330188765x):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;



const int MAXN = 305;

int g[MAXN][MAXN], pro[MAXN];

bool be_deleted[MAXN];



int main() {

	int n, m;

	scanf("%d%d", &n, &m);

	for (register int i = 1; i <= n; i++)

		for (register int j = 1; j <= m; j++)

			scanf("%d", &g[i][j]);

	int ans = n;

	for (register int i = 1; i <= m; i++) {

		memset(pro, 0, sizeof(pro));

		for (register int j = 1; j <= n; j++)

			for (register int k = 1; k <= m; k++) {

				int temp = g[j][k];

				if (!be_deleted[temp]) {

					pro[temp]++;

					break;

				}

			}

		int pos = int(max_element(pro+1, pro+1+m) - pro);

		ans = min(ans, pro[pos]);

		be_deleted[pos] = true;

	}

	printf("%d", ans);

	return 0;

}