#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int n, k = 5, dp[maxn], ans = 0;
;
struct node {
  int a[6], cnt;
  node() {
    cnt = 0;
    fill(a, a + k, 0);
  }
} num[maxn];
bool cmp(node c, node b);
bool cmp2(node c, node b);
int main() {
  ios ::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      num[tmp].a[num[tmp].cnt++] = j;
    }
  }
  sort(num, num + n, cmp);
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = 1;
    for (int j = i + 1; j < n; j++)
      if (cmp2(num[i], num[j])) dp[i] = max(dp[i], dp[j] + 1);
  }
  for (int i = 0; i < n; i++) ans = max(ans, dp[i]);
  cout << ans << '\n';
  return 0;
}
bool cmp(node c, node b) {
  for (int i = 0; i < k; i++) {
    if (c.a[i] < b.a[i]) return true;
    if (c.a[i] > b.a[i]) return false;
  }
  return false;
}
bool cmp2(node c, node b) {
  for (int i = 0; i < k; i++)
    if (c.a[i] >= b.a[i]) return false;
  return true;
}
