import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.chomp.to!int;
  int[] A = new int[N];
  foreach(ref a; A) {
    a = readln.chomp.to!int;
  }

  int[] pal = new int[0];
  foreach(a; A) {
    auto lb = assumeSorted!"a>b"(pal).upperBound(a);
    if(lb.empty) {
      pal ~= a;
    } else {
      lb.front = a;
    }
  }
  pal.length.writeln;
}
