
import std.stdio;
import std.string;

void main()
{
	auto n = readln;
	auto s = readln.strip;
	auto result = size_t.max;
	
	for( int index = 0; index <= s.length; index++ )
	{
		auto xc = turnCount( true, s[ 0 .. index ] );
		if( result < xc ) break;
		auto yc = turnCount( false, s[ index .. $ ] );
		if( result < xc + yc ) continue;
		
		result = xc + yc;
	}
	
	writeln( result );
}

size_t turnCount( in bool turn_east, in string members )
{
	static size_t[ string ] memo;
	
	if( members !in memo )
	{
		switch( members.length )
		{
			case 0:
				memo[ members ] = 0;
				break;
			case 1:
				memo[ members ] = ( members[ 0 ] == 'E' ) ? 0 : 1;
				break;
			default:
				auto center = members.length / 2;
				memo[ members ] = turnCount( true, members[ 0 .. center ] ) + turnCount( true, members[ center .. $ ] );
				break;
		}
	}
	
	if( turn_east ) return memo[ members ];
	else            return members.length - memo[ members ];
}
