#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int a[1010], d[1010], mx[1010];
bool g[1010][1010];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    mx[i] = 1;
    d[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      g[i][j] = 1;
    }
  }
  while (m--) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      g[i][i] = 0;
      for (int j = i; j <= n; j++) {
        g[a[j]][a[i]] = 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (g[i][j]) d[j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == 0) q.push(i);
  }
  int ans = 1;
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= n; i++) {
      if (g[x][i]) {
        d[i]--;
        mx[i] = max(mx[i], mx[x] + 1);
        ans = max(ans, mx[i]);
        if (d[i] == 0) q.push(i);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
