#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
const int K = 6;
int a[N][K];
int p[N];
int L[N];
int n, k;
int check(int i, int j) {
  for (int t = 1; t <= k; t++) {
    if (a[i][t] >= a[j][t]) return 0;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int j = 1; j <= k; j++) {
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      a[x][j] = i;
      if (j == 1) p[i] = x;
    }
  }
  for (int i = 1; i <= n; i++) L[i] = 0;
  L[0] = 0;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int u = p[i];
    int mx = 0;
    for (int j = 1; j <= n; j++)
      if (check(j, u) && L[j] > mx) mx = L[j];
    L[u] = mx + 1;
    res = max(res, L[u]);
  }
  cout << res;
  return 0;
}
