#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int a[5][1005], pos[5][1005];
vector<int> mp[1005];
int dp[1005];
void dfs(int x) {
  if (dp[x]) return;
  dp[x] = 1;
  int mm = 0;
  for (int c : mp[x]) {
    dfs(c);
    mm = max(mm, dp[c]);
  }
  dp[x] += mm;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    for (int(j) = 1; (j) <= (int)(n); (j)++) {
      scanf("%d", &a[i][j]);
      pos[i][a[i][j]] = j;
    }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(n); (j)++) {
      int c = 0;
      for (int(x) = 0; (x) < (int)(k); (x)++)
        if (pos[x][i] < pos[x][j]) c++;
      if (c == k) mp[i].push_back(j);
    }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (dp[i] == 0) dfs(i);
  int ans = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
