#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[1000];
int dp[1000];
int rec(int i) {
if (dp[i] != -1) return dp[i];
int cur = 1;
for (int j : adj[i]) {
cur = max(cur, 1 + rec(j));
}
return dp[i] = cur;
}
signed main() {
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
vector<vector<int>> a(k, vector<int>(n)), pos(k, vector<int>(n));
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
a[i][j]--;
pos[i][a[i][j]] = j;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int ok = 1;
for (int x = 0; x < k; x++) {
ok &= (pos[x][i] < pos[x][j]);
}
if (ok) {
adj[i].push_back(j);
}
}
}
for (int i = 0; i < n; i++) dp[i] = -1;
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, rec(i));
}
cout << ans << '\n';
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCnZlY3RvcjxpbnQ+IGFkalsxMDAwXTsKaW50IGRwWzEwMDBdOwppbnQgcmVjKGludCBpKSB7CglpZiAoZHBbaV0gIT0gLTEpIHJldHVybiBkcFtpXTsKCWludCBjdXIgPSAxOwoJZm9yIChpbnQgaiA6IGFkaltpXSkgewoJCWN1ciA9IG1heChjdXIsIDEgKyByZWMoaikpOwoJfQoJcmV0dXJuIGRwW2ldID0gY3VyOwp9CnNpZ25lZCBtYWluKCkgewoJaW9zX2Jhc2UgOjogc3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKCWludCBuLCBrOyBjaW4gPj4gbiA+PiBrOwoJdmVjdG9yPHZlY3RvcjxpbnQ+PiBhKGssIHZlY3RvcjxpbnQ+KG4pKSwgcG9zKGssIHZlY3RvcjxpbnQ+KG4pKTsKCWZvciAoaW50IGkgPSAwOy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