from collections import deque
import bisect
import sys
sys.setrecursionlimit(10**9)


def main():
    N = int(input())
    X = deque()

    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X,a)

        if j == 0:
            X.appendleft(a)
        else:
            X[j-1] = a


    print(len(X))


if __name__ == "__main__":
  main()

5e77785d745542c2a9ffd8942d002c62624359ea
<mask token>

<mask token>


def main():
    N = int(input())
    X = deque()
    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X, a)
        if j == 0:
            X.appendleft(a)
        else:
            X[j - 1] = a
    print(len(X))


<mask token>

<mask token>
sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    X = deque()
    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X, a)
        if j == 0:
            X.appendleft(a)
        else:
            X[j - 1] = a
    print(len(X))


if __name__ == '__main__':
    main()

from collections import deque
import bisect
import sys
sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    X = deque()
    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X, a)
        if j == 0:
            X.appendleft(a)
        else:
            X[j - 1] = a
    print(len(X))


if __name__ == '__main__':
    main()

from collections import deque
import bisect
import sys
sys.setrecursionlimit(10**9)


def main():
    N = int(input())
    X = deque()

    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X,a)

        if j == 0:
            X.appendleft(a)
        else:
            X[j-1] = a


    print(len(X))


if __name__ == "__main__":
  main()
