#include <bits/stdc++.h>
using namespace std;
int a[7][1010], b[7][1010], n, k, dp[1010];
int main() {
  scanf("%d%d", &n, &k);
  int tmp;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &tmp);
      a[i][j] = tmp;
      b[i][tmp] = j;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    for (int j = 1; j < i; j++) {
      int flag = 0;
      for (int ii = 2; ii <= k; ii++) {
        if (b[ii][a[1][i]] < b[ii][a[1][j]]) flag = 1;
        if (flag) continue;
      }
      if (flag) continue;
      dp[i] = max(dp[j] + 1, dp[i]);
    }
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
