#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
inline long long getPow(long long a, long long b) {
  long long res = 1ll, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
    }
    tp *= tp;
    b >>= 1ll;
  }
  return res;
}
inline long long nxt() {
  long long x;
  cin >> x;
  return x;
}
void ok() {
  puts("YES");
  exit(0);
}
void no() {
  puts("NO");
  exit(0);
}
long long xx[] = {-1, 1, 0, 0};
long long yy[] = {0, 0, -1, 1};
const int N = 1111;
long long ans;
vector<vector<long long>> g(N);
vector<long long> used(N, 0);
vector<long long> w(N);
void dfs(long long v) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    long long x = g[v][i];
    if (!used[x]) {
      dfs(x);
    }
    w[v] = max(w[v], w[g[v][i]] + 1);
  }
  w[v] = max(w[v], 1ll);
  ans = max(ans, w[v]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n = nxt(), k = nxt();
  vector<vector<long long>> perms(k, vector<long long>(n));
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      long long x = nxt() - 1;
      perms[i][x] = j;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      bool ok = 1;
      for (int e = 0; e < k; e++) {
        if (perms[e][j] < perms[e][i]) ok = 0;
      }
      if (ok) {
        g[i].push_back(j);
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    dfs((long long)i);
  }
  cout << ans;
  return 0;
}
