import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Int](N+1)
  for (i <- 1 to N)
    A(i) = in.next().toInt


  //
  val dp = new Array[Int](N+1)
  dp(1) = A(1)
  var cnt = 1

  def check(i: Int): Boolean = {
    dp(i) < n
  }

  // 条件を満たす最小の値を返す
  def binarySearch(min: Int, max: Int, n: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(min, n) match{
          case true  => min
          case false => max
        }
      case _ =>
        (check(mid, n)) match{
          case true  => binarySearch(min, mid)
          case false => binarySearch(mid, max)
        }
    }
  }

  for (i <- 2 to N) {
    val now = A(i)
    if (now <= dp(cnt)) {
      cnt += 1
      dp(cnt) = now
    }
    else {
      val ind = binarySearch(1, ind, now)
      dp(ind) = now
    }
  }

  println(cnt)
}


object LISlen{
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
