Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim a(0 To n - 1) As Long
    Dim c(0 To n) As Long
    For i As Integer = 0 To n - 1
      a(i) = Long.Parse(Console.ReadLine())
      c(i) = -1
    Next
    c(n) = -1
    For i As Integer = 0 To n - 1
      Dim j As Integer = Search(c, a(i), 0, i)
      c(j) = a(i)
    Next
    For i As Integer = 0 To n
      If c(i) = -1 Then
        Console.WriteLine(i.ToString())
        Exit For
      End If
    Next
  End Sub

  Shared Function Search(c As Long(), target As Long, min As Integer, max As Integer) As Integer
    While min < max
      Dim mid As Integer = min + ((max - min) \ 2)
      If c(mid) >= target Then
        min = mid + 1
      Else
        max = mid
      End If
    End While
    Return min
  End Function
End Class