#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;


int main() {
	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]--;
		}
	}

	vector<bool> sp(M, true);
	int ans = 1e8;
	for (int k = 0; k < M - 1; k++) {
		vector<int> num(M);
		int temp = 0, id = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				int a = A[i][j];
				if (sp[a]) {
					num[a]++;
					if (temp < num[a])
						temp = num[a], id = a;
					break;
				}
			}
		}
		//cout << "temp=" << temp << endl;
		sp[id] = false;
		if (temp == 0)continue;
		ans = min(ans, temp);
	}
	cout << (M == 1 ? N : ans) << endl;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, M, A[2000], B[2000];
	int V[2000] = { 0 };
	int max = 0;
	int ans;
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 1; i <= M; i++) {
		scanf("%d", &B[i]);
	}
	for (int i = 1; i <= M; i++) {
		for (int j = 1; i <= N; j++) {
			if (A[j] <= B[i]) {
				V[j]++;
				break;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		//printf("%d\n", V[i]);
		if (max < V[i]) {
			max = V[i];
			ans = i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}