#include <bits/stdc++.h>
using namespace std;
const int modul = 1000000007;
const int nmax = 1100;
const double e = 1e-8;
const double pi = acos(-1);
int n, k, stest, a[10][nmax], F[nmax], pos[10][nmax];
bool check(int u, int v) {
  for (int i = 1; i <= k; i++)
    if (pos[i][u] > pos[i][v]) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) pos[i][a[i][j]] = j;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    F[i] = 1;
    for (int j = 1; j <= i - 1; j++)
      if (check(a[1][j], a[1][i])) F[i] = max(F[i], F[j] + 1);
    res = max(res, F[i]);
  }
  cout << res << endl;
  return 0;
}
