// Arup Guha
// 10/22/2016
// Solution to 2016 NCPC Problem G: Game Rank
// Solved during UCF practice teaming with Travis Meade.

import java.util.Scanner;

public class g {
	public static void main(String[] Args) {
		
		// Just hard code what they gave us.
		int[] target = new int[26];
		for (int i=1; i<=10; i++) target[i] = 5;
		for (int i=11; i<=15; i++) target[i] = 4;
		for (int i=16; i<=20; i++) target[i] = 3;
		for (int i=21; i<=25; i++) target[i] = 2;
		
		// Set up variables.
		Scanner stdin = new Scanner(System.in);
		char[] list = stdin.next().toCharArray();
		int n = list.length;
		
		int rank = 25;
		int stars = 0, streak = 0;
		
		// Go through the sequence of wins and losses.
		for (int i=0; i<n; i++) {
			
			// Master!
			if (rank == 0) break;
			
			// Process a win.
			if (list[i] == 'W') {
				
				// This is easy.
				streak++;
				stars++;
				
				// Case for extra star.
				if (rank > 5 && streak >= 3) stars++;
				
				// See if we moved up a rank.
				if (stars > target[rank]) {
					stars -= target[rank];
					rank--;
				}
			}
			
			// Process a loss.
			else {
				
				// Always true.
				streak = 0;
				
				// What happens when we're rank 20 or better.
				if (rank <= 20) {
					
					// Lose a star.
					stars--;
					
					// Can't fall below rank 20 again.
					if (rank == 20 && stars < 0) stars = 0;
					
					// But otherwise, we can fall down a rank.
					if (stars < 0) {
						rank++;
						stars = target[rank]-1;
					}
				}
				
			}
		}
		
		// Ta da!
		if (rank == 0) System.out.println("Legend");
		else System.out.println(rank);
	}
}
