#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
vector<int> v[maxn];
int dp[maxn];
int a[10][maxn];
int main() {
  int n, K;
  cin >> n >> K;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < n; j++) scanf("%d", &a[i][j]), v[a[i][j]].push_back(j);
  }
  memset(dp, 0, sizeof(dp));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int p = 0;
      for (int k = 0; k < K; k++)
        if (v[a[0][j]][k] > v[a[0][i]][k]) {
          p = 1;
          break;
        }
      if (p == 0) dp[i] = max(dp[i], dp[j]);
    }
    dp[i]++;
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
