Buggy python submission (verdict: Runtime Error):
import io
import sys
from math import ceil


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
4
0
0
0
0
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = [IN_I()]

  for i in range(0, n - 1):
    num = IN_I()

    # print("s:", l)
    # print("num:", num)
    if l[0] >= num:
      l.insert(0, num)
      continue

    inl = 0
    inr = len(l) - 1
    # 1, 2, 3, 4, 5
    for j in range(0, len(l)):
      if inr == inl:
        l.pop(inr)
        break

      mid = ceil((inr - inl) / 2)
      # print(mid, inl, inr)
      if l[mid] == num:
        inr = mid - 1
      elif l[mid] > num:
        inr = mid - 1
      else:
        inl = mid

    inl = 0
    inr = len(l) - 1
    # print("nuita:", l)
    for j in range(0, len(l)):
      mid = ceil((inr - inl) / 2)
      if mid == inl:
        if l[mid] >= num:
          l.insert(mid, num)
        else:
          l.insert(mid + 1, num)
        break
      elif l[mid] == num:
        l.insert(mid, num)
      elif l[mid] > num:
        inr = mid - 1
      else:
        inl = mid + 1

  # print(l)
  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()


Fixed submission:
import io
import sys
from bisect import bisect_right, bisect_left
from collections import deque


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
7
1
0
3
4
1
2
1
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = deque([IN_I()])

  for i in range(0, n - 1):
    num = IN_I()

    idx = bisect_left(l, num)
    if idx == 0:
      l.appendleft(num)
    else:
      l[idx - 1] = num
    # print(l)

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()

Buggy python submission (verdict: Runtime Error):
import io
import sys
from math import ceil


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
4
0
0
0
0
'''


def MAIN():
  T_IN()
  A()


def A():
  n = IN_I()

  l = [IN_I()]

  for i in range(0, n - 1):
    num = IN_I()

    # print("s:", l)
    # print("num:", num)
    if l[0] >= num:
      l.insert(0, num)
      continue

    inl = 0
    inr = len(l) - 1
    # 1, 2, 3, 4, 5
    for j in range(0, len(l)):
      if inr == inl:
        l.pop(inr)
        break

      mid = ceil((inr - inl) / 2)
      # print(mid, inl, inr)
      if l[mid] == num:
        inr = mid - 1
      elif l[mid] > num:
        inr = mid - 1
      else:
        inl = mid

    inl = 0
    inr = len(l) - 1
    # print("nuita:", l)
    for j in range(0, len(l)):
      mid = ceil((inr - inl) / 2)
      if mid == inl:
        if l[mid] >= num:
          l.insert(mid, num)
        else:
          l.insert(mid + 1, num)
        break
      elif l[mid] == num:
        l.insert(mid, num)
      elif l[mid] > num:
        inr = mid - 1
      else:
        inl = mid + 1

  # print(l)
  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()


Fixed submission:
import io
import sys
from bisect import bisect_right, bisect_left
from collections import deque


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
7
1
0
3
4
1
2
1
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = deque([IN_I()])

  for i in range(0, n - 1):
    num = IN_I()

    idx = bisect_left(l, num)
    if idx == 0:
      l.appendleft(num)
    else:
      l[idx - 1] = num
    # print(l)

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()

Buggy python submission (verdict: Runtime Error):
import io
import sys
from math import ceil


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
4
0
0
0
0
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = [IN_I()]

  for i in range(0, n - 1):
    num = IN_I()

    # print(l)
    # print(num)
    if l[0] >= num:
      l.insert(0, num)
      continue

    inl = 0
    inr = len(l) - 1
    # 1, 2, 3, 4, 5
    for j in range(0, len(l)):
      mid = (inr - inl) // 2
      if mid == inl:
        l.pop(0)
        break
      elif l[mid] == num:
        inr = mid - 1
      elif l[mid] > num:
        inr = mid
      else:
        inl = mid + 1

    inl = 0
    inr = len(l) - 1
    # print(l)
    for j in range(0, len(l)):
      mid = ceil((inr - inl) / 2)
      if mid == inl:
        if l[mid] >= num:
          l.insert(mid, num)
        else:
          l.insert(mid + 1, num)
        break
      elif l[mid] == num:
        l.insert(mid, num)
      elif l[mid] > num:
        inr = mid - 1
      else:
        inl = mid + 1


  # print(l)
  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()


Fixed submission:
import io
import sys
from bisect import bisect_right, bisect_left
from collections import deque


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
7
1
0
3
4
1
2
1
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = deque([IN_I()])

  for i in range(0, n - 1):
    num = IN_I()

    idx = bisect_left(l, num)
    if idx == 0:
      l.appendleft(num)
    else:
      l[idx - 1] = num
    # print(l)

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()

Buggy python submission (verdict: Runtime Error):
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
5
5
4
3
5
2
1
'''


def MAIN():
  T_IN()
  A()


def A():
  n = IN_I()

  l = []
  
  snum = -1
  pnum = -1
  for i in range(0, n):
    num = IN_I()
    # print("num:", num )
    if pnum < num:
      pnum = num
      continue

    # print(l, num)
    for j in range(0, len(l) + 1):
      # print(j, len(l))
      if j == len(l):
        # print("l append", pnum)
        l.append(pnum)
      else:
        if l[j] < snum:
          l[j] = pnum
          print (l[j], pnum)
          break

    # print ("pnum", num)
    snum = pnum = num

  if pnum > -1:
    for j in range(0, len(l) + 1):
      if j == len(l):
        l.append(pnum)
      else:
        if l[j] < snum:
          l[j] = pnum
          break

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()


Fixed submission:
import io
import sys
from bisect import bisect_right, bisect_left
from collections import deque


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
7
1
0
3
4
1
2
1
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = deque([IN_I()])

  for i in range(0, n - 1):
    num = IN_I()

    idx = bisect_left(l, num)
    if idx == 0:
      l.appendleft(num)
    else:
      l[idx - 1] = num
    # print(l)

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()

Buggy python submission (verdict: Time Limit Exceeded):
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
4
0
0
0
0
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = []
  for i in range(0, n):
    num = IN_I()
    # print(l, num)
    for j in range(0, len(l) + 1):
      if j == len(l):
        l.append(num)
      else:
        if l[j] < num:
          l[j] = num
          break

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()


Fixed submission:
import io
import sys
from bisect import bisect_right, bisect_left
from collections import deque


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
7
1
0
3
4
1
2
1
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()

  l = deque([IN_I()])

  for i in range(0, n - 1):
    num = IN_I()

    idx = bisect_left(l, num)
    if idx == 0:
      l.appendleft(num)
    else:
      l[idx - 1] = num
    # print(l)

  print(len(l))
  return None


def B():
  return None


def C():
  return None


MAIN()