// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < ll, ll > pl;
typedef vector < pi > vi;
typedef vector < pi > vl;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-6;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

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

int ptr[305], cnt[305];
bool bad[305];

bool check(int x) {
    for (int i = 1; i <= n; i++)
        ptr[i] = 1;
    for (int i = 1; i <= m; i++)
        bad[i] = 0;
    while(1) {
        for (int i = 1; i <= m; i++)
            cnt[i] = 0;
        for (int i = 1; i <= n; i++)
            cnt[a[i][ptr[i]]]++;
        bool flag = 0;
        for (int i = 1; i <= n; i++) {
            if (cnt[a[i][ptr[i]]] > x || bad[a[i][ptr[i]]]) {
//                cout << "shit bading " << a[i][ptr[i]] << endl;
                bad[a[i][ptr[i]]] = 1;
                while(ptr[i] <= m && bad[a[i][ptr[i]]])
                    ptr[i]++;
                if (ptr[i] == m + 1)
                    return 0;
                flag = 1;
            }
        }
        if (!flag) {
//            for (int i = 1; i <= n; i++)
//                cout << ptr[i] << ' ';
//            cout << endl;
            return 1;
        }
    }
    assert(0);
}

int u[305], slow[305];

int calc(vector < int > q) {
    memset(u, 0, sizeof u), memset(slow, 0, sizeof slow);
    for (auto i : q)
        u[i] = 1;
    int maxi = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (u[a[i][j]]) {
                slow[a[i][j]]++;
                maxi = max(maxi, slow[a[i][j]]);
                break;
            }
        }
    return maxi;
}

int slowSol() {
    int mini = inf;
    for (int mask = 1; mask < (1 << m); mask++) {
        vector < int > q;
        for (int i = 0; i < m; i++)
            if (mask & (1 << i))
                q.pb(i + 1);
        mini = min(mini, calc(q));
    }
    return mini;
//    cout << "slow is " << mini << endl;
}

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

void gen() {
    srand(time(0));
    n = rand() % 5 + 1;
    m = rand() % 10 + 1;
    cout << n << ' ' << m << endl;
    vector < int > now;
    for (int i = 1; i <= m; i++)
        now.pb(i);
    for (int i = 1; i <= n; i++) {
        random_shuffle(now.begin(), now.end());
        int it = 0;
        for (auto j : now) {
            a[i][++it] = j;
            cout << j << ' ';
        }
        cout << endl;
    }
}

int fastSol() {
    for (int i = 1; i <= n; i++)
        if (check(i)) {
            return i;
        }
    assert(0);
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    read();
    cout << fastSol() << endl;
    return 0;
    for (int it = 0; ; it++) {
        gen();
        if (fastSol() != slowSol()) {
            cout << "shit " << fastSol() << ' ' << slowSol() << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 640