#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[10][1010], p[10][1010], dp[1010];
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= n; j++) {
        scanf("%d", &a[i][j]);
        p[i][a[i][j]] = j;
      }
    }
    for (int i = 1; i <= n; i++) dp[i] = 1;
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j < i; j++) {
        int cnt = 1;
        for (int z = 2; z <= k; z++) {
          if (p[z][a[1][j]] > p[z][a[1][i]]) cnt = 0;
        }
        if (cnt) dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (dp[i] > ans) ans = dp[i];
    }
    printf("%d\n", ans);
  }
  return 0;
}
