#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int N = 1003;
int a[5][N], nop[N], b[5][N];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int j = 0; j < k; ++j)
    for (int i = 0; i < n; ++i) {
      cin >> a[j][i];
      b[j][a[j][i] - 1] = i;
    }
  for (int i = 0; i < n; ++i) {
    nop[i] = 1;
    for (int j = 0; j < i; ++j) {
      bool T = true;
      for (int l = 1; l < k; ++l) {
        if (b[l][a[0][i] - 1] < b[l][a[0][j] - 1]) {
          T = false;
          break;
        }
      }
      if (T) nop[i] = max(nop[j] + 1, nop[i]);
    }
  }
  cout << *max_element(nop, nop + n);
  return 0;
}
