#include <bits/stdc++.h>
using namespace std;
int N, K, pos[6][1001], dp[1001];
vector<int> way[1001];
int dfs(int n) {
  if (dp[n]) return dp[n];
  for (int i = 0; i < (int)way[n].size(); i++)
    dp[n] = max(dp[n], dfs(way[n][i]));
  return ++dp[n];
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= K; i++)
    for (int j = 1, a; j <= N; j++) {
      scanf("%d", &a);
      pos[i][a] = j;
    }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j) {
        bool ctrl = 1;
        for (int k = 1; k <= K; k++)
          if (pos[k][i] > pos[k][j]) {
            ctrl = 0;
            break;
          }
        if (ctrl) way[i].push_back(j);
      }
  int ans = 0;
  for (int i = 1; i <= N; i++) dfs(i);
  for (int i = 1; i <= N; i++) ans = max(dp[i], ans);
  printf("%d\n", ans);
  return 0;
}
