There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.

Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.

Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.

Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.

Input

The first line contains a sequence of letters without spaces s1s2... sn (1 ≤ n ≤ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.

Output

Print a single integer — the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.

Examples

Input

MFM


Output

1


Input

MMFF


Output

3


Input

FFMMM


Output

0

Note

In the first test case the sequence of changes looks as follows: MFM →  FMM.

The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF →  MFMF →  FMFM →  FFMM.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/*
 * There are n schoolchildren, boys and girls, lined up in the school canteen 
 * in front of the bun stall. The buns aren't ready yet and the line is
 * undergoing some changes.
 * 
 * Each second all boys that stand right in front of girls, simultaneously 
 * swap places with the girls (so that the girls could go closer to the 
 * beginning of the line). In other words, if at some time the i-th position 
 * has a boy and the (i + 1)-th position has a girl, then in a second, 
 * the i-th position will have a girl and the (i + 1)-th one will have a boy.
 * 
 * Let's take an example of a line of four people: a boy, a boy, a girl, 
 * a girl (from the beginning to the end of the line). 
 * Next second the line will look like that: a boy, a girl, a boy, a girl. 
 * Next second it will be a girl, a boy, a girl, a boy. 
 * Next second it will be a girl, a girl, a boy, a boy.
 * The line won't change any more.
 * 
 * Your task is: given the arrangement of the children in the line to 
 * determine the time needed to move all girls in front of boys 
 * (in the example above it takes 3 seconds). Baking buns takes a 
 * lot of time, so no one leaves the line until the line stops changing.
 * 
 * Input
 * The first line contains a sequence of letters without spaces s1s2... sn 
 * (1 ≤ n ≤ 106), consisting of capital English letters M and F. 
 * If letter si equals M, that means that initially, the line had a 
 * boy on the i-th position. If letter si equals F, then initially the line 
 * had a girl on the i-th position.
 * 
 * Output
 * Print a single integer — the number of seconds needed to move all 
 * the girls in the line in front of the boys. If the line has only 
 * boys or only girls, print 0.
 */

/**
 * @author Arief Rahman
 */
public class Queue {
	/*
	 * @param queue the queue of girls (F) and boys (M).
	 * @return true when all girls (F) are in front of boys (B) in the queue.
	 * @return true when the queue are all girls (F) or all boys (B).
	 */
	private static boolean isAligned(List<String> queue) {
		if(queue.indexOf("F") == -1) {
			return true;
		} else if(queue.indexOf("M") == -1) {
			return true;
		} else {
			boolean aligned = true;
			int pos = queue.indexOf("F");
			while(queue.indexOf("F") != -1) {
				int queueSize = queue.size();
				if(pos == 0) {
					queue.remove(0);
				} else if(pos != queueSize - 1) {
					if(queue.get(pos - 1).equals("M")) {
						aligned = false;
						break;
					} else {
						queue = queue.subList(pos + 1, queueSize);
					}
				}
				pos++;
			}
			return aligned;
		}
	}
	
	// Conventional way
//	public static void main(String[] args) {
//		// Read input
//		Scanner in = new Scanner(System.in);
//		String input = in.nextLine();
//		
//		// Create queue for the boys and girls
//		List<String> queue = new ArrayList<> ();
//			
//		// Fill the queues according to input
//		queue.addAll(Arrays.asList(input.split("(?!^)")));
//			
//		// Time for switching (in seconds)
//		int time = 0;
//		
//		// The position of the last girls
//		int lastGirl = queue.lastIndexOf("F");
//		
//		// Start switching.
//		while (!isAligned(queue)) {
//			// List of positions to switch
//			List<Integer> toSwitch = new ArrayList<> ();
//				
//			// Check all positions possible for switching
//			for(int i = 0; i < queue.size() - 1; i++) {
//				// Add to switch list if a girl is behind a boy
//				if(queue.get(i).equals("M") && 
//						queue.get(i + 1).equals("F")) {
//					toSwitch.add(i);
//				}
//				
//				// Break when the last girl is already checked
//				if(lastGirl == i + 1) {
//					break;
//				}
//			}
//			
//			// Switch every position in switch list
//			for(Integer i : toSwitch) {
//				queue.set(i, "F");
//				queue.set(i + 1, "M");
//			}
//			
//			// Add 1 second
//			time++;
//		}
//		
//		// Print the time
//		System.out.println(time);
//	}
	
	// Fast way
	public static void main(String[] args) {
		// Read input
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		
		// Create queue for the boys and girls
		char[] queue = input.toCharArray();
			
		// Time for switching (in seconds)
		int time = 0;
		
		// Find the first not girl's position
		int pos = 0;
		int queueSize = queue.length;
		for(;pos < queueSize && queue[pos] == 'F' ; pos++) {
		}
		
		// Count the time for getting the girls to the front
		/*
		 * To do this without affecting the queue itself (reducing time) :
		 * - If there are only girls or boys, print 0
		 * - Else, check the next position (current boy's position + 1).
		 * If it is a girl, then find which time is the longest between
		 * current longest time + 1 and the time for the girl to travel to the
		 * first male position.
		 */
		
		if(pos != queueSize + 1) {
			for (int i = pos + 1; i < queueSize; i++) {
				if (queue[i] == 'F') {
					time = Math.max(time + 1,i - pos);
					pos++;
				}
			}
		}

		// Print the time
		System.out.println(time);
	}
}
