#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long N = 3e5 + 5;
int n, m, a[N], f[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int id1 = lower_bound(a + 1, a + i, a[i]) - a;
    int id2 = id1 - 1;
    f[i] = 1;
    if (id1 < i) f[i] = max(f[i], f[id1] + 1);
    if (id2 < i) f[i] = max(f[i], f[id2] + 1);
  }
  cout << *max_element(f + 1, f + 1 + n) << '\n';
  return 0;
}
