// Arup Guha
// 10/13/2012
// Solution to 2012 NCPC Problem D: Doorman

import java.util.*;

public class doorman {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		String s = stdin.next();
		
		int ans = 0;
		int cnt = 0;
		boolean flag = true;
		
		// Go through the string.
		for (int i=0; i<s.length(); i++) {
			
			// Just toggle a count.
			if (s.charAt(i) == 'M')
				cnt++;
			else
				cnt--;
			
			// This is too far, break out.
			if (Math.abs(cnt) > n+1) {
				ans = i - 1;
				break;
			}
		}
		
		// If we never broke out, just look at the absolute value of the different.
		if (ans == 0) {
			if (Math.abs(cnt) > n)
				ans = s.length()-1;
			else
				ans = s.length();
		}
		
		// Ta da!
		System.out.println(ans);
	}
}