#include #include #include #include #include #include #include #include #include #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define P pair #define MOD 1000000007 #define INF 1012345678 #define NINF (-2147483647-1) #define LLINF 9223372036854775807 using ll = long long; using namespace std; int main() { int N; cin >> N; vector A(N+1, INF); for (int i = 0; i < N; i++) { int a; cin >> a; int r = N, l = -1; while (r - l > 1) { int mid = (r + l) / 2; if (A[mid] >= a) r = mid; else l = mid; } A[r] = a; } int r = N, l = -1; while (r - l > 1) { int mid = (r + l) / 2; if (A[mid] >= INF) r = mid; else l = mid; } cout << N - r << endl; getchar(); getchar(); return 0; }