#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	
	int a[301][301];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			cin >> a[i][j];
		}
	}
	
	vector<int> erased;
	int ans = 1e9;
	for(int k = 0;k < m;k++){
		map<int,int> p;
		for(int i = 1;i <= m;i++) p[i] = 0;
		
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(find(erased.begin(),erased.end(),a[i][j]) == erased.end()){
					p[a[i][j]]++;
					break;
				}
			}
		}
		
		int mp = 0;
		int num = 0;
		for(int i=1;i <= m;i++){
			if(mp < p[i]){
				mp = p[i];
				num = i;
			}
		}
		ans = min(ans,mp);
		erased.push_back(num);
	}
	
	cout << ans << endl;
	return 0;
}