unittest
{
	assert( [ "5", "2", "1", "4", "5", "3" ].solve == 2 );
	assert( [ "4", "0", "0", "0", "0" ].solve == 4 );
}



import std.container;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	
	auto rbt = redBlackTree!( true, long )();
	foreach( a; as )
	{
		auto ls = rbt.lowerBound( a );
		if( !ls.empty ) rbt.removeKey( ls.back );
		rbt.insert( a );
	}
	return rbt.length;
}
