import java.io.*;

public class Probelm4
{

    public static void main (String[] args) throws IOException
    {

	FileReader inFile = new FileReader ("DATA4.txt");
	FileWriter outFile = new FileWriter ("OUT4.txt");

	BufferedReader in = new BufferedReader (inFile);
	BufferedWriter out = new BufferedWriter (outFile);
	for (int count12 = 0 ; count12 <= 4 ; count12++)
	{
	    String line;
	    int line1 = 0;
	    char[] [] array = new char [10] [10];
	    int time = 0;

	    while ((line = in.readLine ()) != null)
	    {



		for (int count1 = 0 ; count1 <= 9 ; count1++)
		{
		    array [count1] [line1] = line.charAt (count1);
		}
		if (line1 == 9)
		{
		    break;
		}
		else
		{
		    line1++;
		}



	    }




	    for (int count9 = 0 ; count9 <= 20 ; count9++)
	    {
		for (int count1 = 0 ; count1 <= 9 ; count1++)
		{
		    for (int count2 = 0 ; count2 <= 9 ; count2++)
		    {

			if (array [count2] [count1] == 'F')
			{

			    if (count1 > 0)
			    {
				if (array [count2] [count1 - 1] == 'T')
				{
				    array [count2] [count1 - 1] = 'F';
				}
			    }
			    if (count1 < 9)
			    {
				if (array [count2] [count1 + 1] == 'T')
				{
				    array [count2] [count1 + 1] = 'F';
				}
			    }
			    if (count2 > 0)
			    {
				if (array [count2 - 1] [count1] == 'T')
				{
				    array [count2 - 1] [count1] = 'F';
				}
			    }
			    if (count2 < 9)
			    {
				if (array [count2 + 1] [count1] == 'T')
				{
				    array [count2 + 1] [count1] = 'F';
				    count2++;
				}
			    }

			}


		    }


		}
		test:
		for (int count4 = 0 ; count4 <= 9 ; count4++)
		{
		    for (int count5 = 0 ; count5 <= 9 ; count5++)
		    {
			if (array [count5] [count4] == 'T')
			{
			    time++;
			    break test;
			}
		    }

		}


	    }



	    time += 1;
	    for (int count1 = 0 ; count1 <= 9 ; count1++)
	    {
		for (int count2 = 0 ; count2 <= 9 ; count2++)
		{
		    if (array [count2] [count1] == 'T')
		    {
			time = -1;
		    }
		}

	    }



	    System.out.println (time);

	    in.readLine ();
	    out.write (time + "");
	    out.newLine ();
	}
	in.close ();
	out.close ();

    }
}




