#include <bits/stdc++.h>
using namespace std;
int edge[1010][1010];
int arr[1010];
int dp[1010];
int n, k;
int func(int now) {
  int &ret = dp[now];
  if (ret != -1) return ret;
  ret = 1;
  for (int i = 1; i <= n; ++i) {
    if (edge[now][i] == k) {
      ret = max(ret, 1 + func(i));
    }
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; ++i) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &arr[i]);
      for (int j = 0; j < i; ++j) {
        edge[arr[j]][arr[i]]++;
      }
    }
  }
  memset((dp), -1, sizeof(dp));
  ;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, func(i));
  }
  printf("%d\n", ans);
  return 0;
}
