using System;

namespace DPL_1_D_Longest_Increasing_Subsequence
{
	class Program
	{
		static void Main ( string[] args )
		{
			int inputCount = int.Parse (Console.ReadLine ());
			int[] elements = new int[inputCount];

			for (int lp = 0; lp < inputCount; lp++)
			{
				elements[lp] = int.Parse (Console.ReadLine ());
			}

			var result = LongestIncreasingSubsequence (elements);
			Console.WriteLine (result);
		}

		static int LongestIncreasingSubsequence ( int[] numArray )
		{
			int[] temporaryArray = new int[numArray.Length];
			temporaryArray[0] = numArray[0];
			int length = 1;

			for (int lp = 1; lp < numArray.Length; lp++)
			{
				if (temporaryArray[length - 1] < numArray[lp])
				{
					temporaryArray[length++] = numArray[lp];
				}
				else
				{
					int index = LowerBound (numArray, numArray[lp]);
					temporaryArray[index] = numArray[lp];
				}
			}

			return length;
		}

		static int LowerBound ( int[] numArray, int element )
		{
			int lower = 0;
			int upper = numArray.Length;

			while (1 < upper - lower)
			{
				int middleIndex = (lower + upper) / 2;

				if (numArray[middleIndex] < element)
				{
					lower = middleIndex;
				}
				else
				{
					upper = middleIndex;
				}
			}

			if (numArray[lower] < element)
			{
				return upper;
			}
			else
			{
				return lower;
			}
		}
	}
}

