import java.util.*;
import java.io.*;

public class p4{
	public static void main(String [] args)throws IOException{
		
		Scanner input = new Scanner(new File("DATA4.txt"));
		PrintWriter writer = new PrintWriter(new File ("OUT4.txt"));
		
		while(input.hasNext()){
			
			int count = 0;
			
			boolean treesLeft = true;
			boolean [] [] fire = new boolean[12][12];
			String [] line = new String [10];
			String [] [] map = new String [10] [10];
			
			for(int i = 0; i < 10; i++){
				
				line[i] = input.nextLine();
				
				for(int j = 0; j < 9; j++){
					
					map[i][j] = line[i].substring(j, j + 1);
					
				}
			}
			String garbage = input.nextLine();
			
			String [] [] newMap = new String [12] [12];
			
			for(int i = 0; i < 12; i++){
				for(int j = 0; j < 12; j++){
					
					newMap [i] [j] = ".";
					
				}
			
			}
			
			for(int i = 0; i < 10; i++){
				for(int j = 0; j < 10; j++){
					
					newMap[i + 1] [j + 1] = map[i] [j];
					
					if(newMap[i] [j].equals("F")){
						fire[i] [j] =true;
					}
				
			
			
					if(newMap[i] [j].equals("F")){
						fire[i] [j] =true;
					}
				}
			}
			
			for(int i = 0; i < 12; i++){
				for(int j = 0; j < 12; j++){
					
					newMap[i][10] =".";
				}
			}
			
			for(int i = 0; i < 12; i++){
				for(int j = 0; j < 12; j++){
					fire[i] [j] = false;
					if(newMap[i][j].equals("F")){
						fire[i] [j] =true;
					}
				}
			}
			
			while(treesLeft){
				treesLeft = false;
				
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if(fire[i][j]){
							if(newMap[i] [j - 1].equals("T")){
								fire [i] [j - 1] = true;
								treesLeft = true;
							}
							if(newMap[i] [j + 1].equals("T")){
								fire [i] [j + 1] = true;
								treesLeft = true;
							}
							if(newMap[i + 1] [j].equals("T")){
								fire [i + 1] [j] = true;
								treesLeft = true;
							}
							if(newMap[i - 1] [j].equals("T")){
								fire [i - 1] [j] = true;
								treesLeft = true;
							}
						}
					}
				}
				count++;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if(fire[i][j]){
							newMap[i][j]=("F");
						}
					}
				}
			}
			if(count == 1){
				writer.println("-1");
			}
			else{
				writer.println(count);
			}
		}
		writer.close();
	}
}	
