#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, k, a[N], num[N], sumn[N];
set<long long> s;
vector<long long> v(N);
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    for (long long i = 0; i <= a[i]; i++) {
      v[a[i]] = max(v[a[i]], v[i]++);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans = max(v[a[i]], ans);
  }
  cout << ans;
}
