#include <bits/stdc++.h>
using namespace std;
vector<int> pos[1005];
int dp[1005];
int main() {
  int n, k, x;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &x);
      pos[x].push_back(j);
    }
  }
  sort(pos + 1, pos + n + 1);
  int ans = 1;
  for (int i = 1; i <= n; ++i) dp[i] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      bool ok = true;
      for (int l = 0; l < k; ++l) {
        if (pos[j][l] > pos[i][l]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        dp[i] = max(dp[j] + 1, dp[i]);
      }
    }
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
