import java.io.*;
import java.awt.*;
public class prob3
{
    public static void main (String[] args) throws IOException
    {
	BufferedReader in = new BufferedReader (new FileReader ("DATA4.txt"));
	PrintWriter out = new PrintWriter (new FileWriter ("OUT4.txt"));
	for (int bla = 1 ; bla <= 5 ; bla++)
	{
	    boolean flag = false;
	    int count = 0;

	    char map[] [] = new char [10] [10];

	    for (int y = 0 ; y < 10 ; y++)
	    {
		String line = in.readLine ();
		for (int x = 0 ; x < 10 ; x++)
		{
		    map [y] [x] = line.charAt (x);
		}
	    }


	    while (true)
	    {
		flag = false;
		for (int x = 0 ; x < 10 ; x++)
		{
		    for (int y = 0 ; y < 10 ; y++)
		    {
			if (map [x] [y] == 'F')
			{
			    if (x > 0 && map [x - 1] [y] == 'T')
			    {
				map [x - 1] [y] = '*';
				if (flag == false)
				{
				    flag = true;
				    count++;
				}
			    }
			    if (x < 9 && map [x + 1] [y] == 'T')
			    {
				map [x + 1] [y] = '*';
				if (flag == false)
				{
				    flag = true;
				    count++;
				}
			    }
			    if (y > 0 && map [x] [y - 1] == 'T')
			    {
				map [x] [y - 1] = '*';
				if (flag == false)
				{
				    flag = true;
				    count++;
				}
			    }
			    if (y < 9 && map [x] [y + 1] == 'T')
			    {
				map [x] [y + 1] = '*';
				if (flag == false)
				{
				    flag = true;
				    count++;
				}
			    }
			}
		    }
		}
		for (int x = 0 ; x < 10 ; x++)
		{
		    for (int y = 0 ; y < 10 ; y++)
		    {
			if (map [x] [y] == '*')
			{
			    map [x] [y] = 'F';
			}
		    }
		}

		if (flag == false)
		    break;
	    }
	    for (int x = 0 ; x < 10 ; x++)
	    {
		for (int y = 0 ; y < 10 ; y++)
		{
		    if (map [x] [y] == 'T')
		    {
			count = -1;
			break;
		    }
		}
	    }
	    out.println (count);
	}
	out.close ();
    }
}

