import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class Problem4 {
	public static void main(String[] args) throws FileNotFoundException
	{
		Scanner scanner = new Scanner(new File("DATA4.txt"));
		PrintWriter pw = new PrintWriter(new File("OUT4.txt"));
		
		for(int x = 0; x < 5; x++)
		{
			int numTrees = 0;
			ArrayList<Pos> queue = new ArrayList<Pos>(); 
			char[][] map = new char[10][10];
			for(int i = 0; i < 10; i++)
			{
				String s = scanner.nextLine();
				for(int j = 0 ; j < 10; j++)
				{
					map[i][j] = s.charAt(j);
					if(map[i][j] == 'F')
					{
						queue.add(new Pos(i,j,0));
					}
					if(map[i][j] == 'T')
					{
						numTrees++;
					}
				}
			}
			scanner.nextLine();
			int turn = 0;
			int lastTrees = numTrees;
			while(true)
			{
				if(queue.size() == 0)
				{
					pw.println("-1");
					break;
				}
				numTrees -= process(map, queue, numTrees);
				
				if(queue.get(0).turn > turn)
				{
					turn++;
					if(numTrees == lastTrees)
					{
						pw.println("-1");
						break;
					}
					else
					{
						lastTrees = numTrees;
					}
				}
				
				if(numTrees == 0)
				{
					pw.println(queue.get(0).turn + 1);
					break;
				}
				queue.remove(0);
			}
			
			
		}
		
		pw.close();
	}
	
	public static int process(char[][] map, ArrayList<Pos> queue, int numTrees)
	{
		Pos p = queue.get(0);
		int returned = 0;
		//Up
		if(p.row > 0 && map[p.row - 1][p.col] == 'T')
		{
			map[p.row-1][p.col] = 'F';
			queue.add(new Pos(p.row-1, p.col, p.turn+1));
			returned++;
		}
		//Down
		if(p.row < 9 && map[p.row + 1][p.col] == 'T')
		{
			map[p.row+1][p.col] = 'F';
			queue.add(new Pos(p.row+1, p.col, p.turn+1));
			returned++;
		}
		//Left
		if(p.col > 0 && map[p.row][p.col - 1] == 'T')
		{
			map[p.row][p.col-1] = 'F';
			queue.add(new Pos(p.row, p.col-1, p.turn+1));
			returned++;
		}
		
		if(p.col < 9 && map[p.row][p.col + 1] == 'T')
		{
			map[p.row][p.col+1] = 'F';
			queue.add(new Pos(p.row, p.col+1, p.turn+1));
			returned++;
		}
		return returned;
	}

}

class Pos
{
	int row,col,turn;
	public Pos(int row, int col, int turn)
	{
		this.row = row;
		this.col = col;
		this.turn = turn;
	}
}

