#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1010;
const int M = 10;
int n, k;
int a[M][N], in[N], ans;
int h[N << 1], e[N << 1], ne[N << 1], cnt;
bool check(int x, int y) {
for(int i = 1; i <= k; ++ i)
if(a[i][x] >= a[i][y]) return 0;
return 1;
}
void add(int u, int v) {
e[++ cnt] = v, ne[cnt] = h[u], h[u] = cnt;
}
void dfs(int u, int sum) {
ans = max(ans, sum);
for(int i = h[u]; i; i = ne[i]) {
int v = e[i];
dfs(v, sum + 1);
}
}
int main() {
cin >> n >> k;
for(int i = 1; i <= k; ++ i)
for(int j = 1; j <= n; ++ j) {
int x; cin >> x;
a[i][x] = j;
}
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= n; ++ j)
if(check(i, j)) {
add(i, j);
++ in[j];
}
for(int i = 1; i <= n; ++ i)
if(!in[i]) dfs(i, 1);
cout << ans;
return 0;
}