#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	int n, m;
	cin >> n >> m;
	vector <vector <int>> a(n, vector <int> (m));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	int g = 1e9;
	vector <bool> done(m, false);
	int iter = 0;
	while(iter < m) {
		vector <int> cnt(m, 0);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(!done[a[i][j]]) {
					cnt[a[i][j]]++;
					break;
				}
			}
		}
		int el = max_element(all(cnt)) - cnt.begin();
		g = min(g, cnt[el]);
		done[el] = true;
		iter++;
	}
	cout << g << 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;
}