import java.util.*;
import java.io.*;

public class Lol4
{
    static int[] [] map;
    static boolean done;
    public static boolean burnEverything (int x, int y)
    {
	boolean changed = false;
	try
	{
	    if (map [x - 1] [y] == 1)
	    {
		map [x - 1] [y] = 3;
		changed = true;
	    }
	}
	catch (ArrayIndexOutOfBoundsException a)
	{
	}
	try
	{
	    if (map [x + 1] [y] == 1)
	    {
		map [x + 1] [y] = 3;
		changed = true;
	    }
	}
	catch (ArrayIndexOutOfBoundsException a)
	{
	}
	try
	{
	    if (map [x] [y - 1] == 1)
	    {
		map [x] [y - 1] = 3;
		changed = true;
	    }
	}
	catch (ArrayIndexOutOfBoundsException a)
	{
	}
	try
	{
	    if (map [x] [y + 1] == 1)
	    {
		map [x] [y + 1] = 3;
		changed = true;
	    }
	}
	catch (ArrayIndexOutOfBoundsException a)
	{
	}
	return (changed);
    }


    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 asd = 0 ; asd < 5 ; asd++)
	{
	    map = new int [10] [10];
	    if (asd != 0)
	    {
		in.readLine ();
	    }
	    for (int x = 0 ; x < 10 ; x++)
	    {
		String temp = in.readLine ();
		for (int y = 0 ; y < 10 ; y++)
		{
		    if (temp.charAt (y) == 'T')
		    {
			map [x] [y] = 1;
		    }
		    else if (temp.charAt (y) == 'F')
		    {
			map [x] [y] = 2;
		    }
		    else
		    {
			map [x] [y] = 0;
		    }
		}
	    }
	    int counter = 0;
	    while (true)
	    {
		done = true;
		for (int x = 0 ; x < 10 ; x++)
		{
		    for (int y = 0 ; y < 10 ; y++)
		    {
			if (map [x] [y] == 2)
			{
			    if (burnEverything (x, y))
			    {
				done = false;
			    }
			}
		    }
		}
		if (done)
		{
		    break;
		}
		else
		{
		    counter++;
		}
		for (int x = 0 ; x < 10 ; x++)
		{
		    for (int y = 0 ; y < 10 ; y++)
		    {
			if (map [x] [y] == 3)
			{
			    map [x] [y] = 2;
			}
		    }
		}
	    }
	    boolean lol = true;
	    for (int x = 0 ; x < 10 ; x++)
	    {
		for (int y = 0 ; y < 10 ; y++)
		{
		    if (map [x] [y] == 1 || counter == 0)
		    {
			out.println ("-1");
			x = 11;
			lol = false;
			break;
		    }
		}
	    }
	    if (lol)
		out.println (counter);
	    out.flush ();
	}
	out.close ();
    }
}



