#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = N * N;
int a[10][N], p[10][N];
int n, k, dis[N], deg[N];
int head[N], pre[M], nxt[M], e;
bool vis[N];
void init() {
  memset(head, -1, sizeof(head));
  e = 0;
}
void addedge(int u, int v) { pre[e] = v, nxt[e] = head[u], head[u] = e++; }
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; ++i)
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &a[i][j]);
      p[i][a[i][j]] = j;
    }
  init();
  memset(deg, 0, sizeof(deg));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      bool flag = true;
      for (int z = 0; z < k; ++z) {
        if (p[z][j] <= p[z][i]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        addedge(i, j);
        ++deg[j];
      }
    }
  }
  for (int i = 1; i <= n; ++i) dis[i] = 1;
  memset(vis, 0, sizeof(vis));
  for (int j = 1; j <= n; ++j) {
    for (int i = 1; i <= n; ++i)
      if (deg[i] == 0 && !vis[i]) {
        vis[i] = 1;
        for (int t = head[i]; ~t; t = nxt[t]) {
          int v = pre[t];
          --deg[v];
          dis[v] = max(dis[v], dis[i] + 1);
        }
        break;
      }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, dis[i]);
  printf("%d\n", ans);
  return 0;
}
