using System; using System.Linq; namespace _365 { class Program { public static int LowerBound(int[] arr,int value) { int low = 0; int high = arr.Length; int mid; while (low < high) { mid = ((high - low) / 2) + low; if (arr[mid] < value) low = mid + 1; else high = mid; } return low; } static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] dp = new int[n]; for (int i = 0; i < n; i++) dp[i] = 1000000000; for (int i = 0; i < n; i++) { dp[LowerBound(dp,x[i])] = x[i]; } Console.WriteLine(n - LowerBound(dp,1000000000)); } } }