#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, k;
vector<int> b, lis[N];
int f[N];
int ans = 0;
bool check(int x, int y) {
  for (int i = 0; i < k; i++) {
    if (lis[x][i] <= lis[y][i]) return false;
  }
  return true;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) {
      int a;
      cin >> a;
      if (i == 0) b.push_back(a);
      lis[a].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++)
      if (check(b[i], b[j])) f[b[i]] = max(f[b[i]], f[b[j]] + 1);
    ans = max(ans, f[b[i]]);
  }
  cout << ans + 1 << endl;
}
