let n = Int(readLine()!)!
var a: [Int] = .init(repeating: 0, count: n)
for i in 0..<n {
  a[i] = Int(readLine()!)!
}
var ans: [Int] = []

func binarySearch(_ a: [Int], _ target: Int) -> Int {
  var left = 0
  var right = ans.count - 1
  var ans = a.count
  while left <= right {
    let mid = left + (right - left) / 2
    if target < a[mid] {
      ans = mid
      left = mid + 1
    } else {
      right = mid - 1
    }
  }
  return max(ans, 0)
}

for i in 0..<n {
  let ai = -a[i]
  let index = binarySearch(ans, ai)
  if index >= ans.count {
    ans.append(ai)
  } else {
    ans[index] = ai
  }
}
print(ans.count)