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



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

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

auto parse( 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 );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto cs = new long[ as.length ];
	cs[] = -1;
	auto cs_s = cs.assumeSorted!( ( x, y ) => y < x );
	LOOP: foreach( a; as )
	{
		auto i = cs_s.lowerBound( a - 1 ).length;
		cs[ i ] = a;
		if( ans <= i ) ans++;
	}
	return ans;
}
