var
  f: Text;
  i, j, v, N, c: Integer;
  A, R, P: array [0..10001] of Integer;

begin
//  Assign(f, 'input.txt'); Reset(f);
  A[0] := MaxInt; A[10001] := -1;
  R[0] := 10001;
  Readln(N); c := 0;
  for i := 1 to N do begin
    if Eof then break;
    Read(v); A[i] := v;
    for j := 0 to High(R) - 1 do begin
      if (A[R[j]] < v) and (v < A[R[j + 1]]) then begin
        P[i] := R[j];
        R[j + 1] := i;
        break;
      end;
    end;
  end;
//  Close(f);
//  Assign(f, 'output.txt'); Rewrite(f);
  for i := 1 to 10000 do
    if A[R[i]] = MaxInt then break;
  i := R[i - 1]; j := 0;
  while i < 10001 do begin
    Inc(j); R[j] := A[i];
    i := P[i];
  end;
  for i := j downto 1 do begin
    {Write(f, R[i], ' ');}
    Inc(c);
  end;
  Writeln(c);
//  Close(f);
end.
