import java.io.*;
/**
 *
 * @author rusud3509
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        File file = new File("DATA3.txt");
        File file2 = new File("OUT3.txt");
        FileReader input = new FileReader(file);
        FileWriter output = new FileWriter(file2);
        BufferedReader in = new BufferedReader(input);
        BufferedWriter out = new BufferedWriter(output);
        String line;
        char[][] forest = new char[10][10];
        while ((line = in.readLine()) != null) {
            for (int y = 0; y < 10; y++) {
                for (int x = 0; x < 10; x++) {
                    forest[x][y] = line.charAt(x);
                }
                line = in.readLine();
            }

            
            int iter = 0;
            int trees = 0, oldTrees = 1;
            do {
                if (oldTrees != trees) {
                    oldTrees = trees;
                    trees = 0;
                    for (int y = 0; y < 10; y++) {
                        for (int x = 0; x < 10; x++) {
                            if (forest[x][y] == 'T') {
                                trees++;
                            }
                            if (forest[x][y] == 'F') {
                                if (y < 10 && forest[x][y + 1] == 'T') {
                                    forest[x][y + 1] = 'F';
                                }
                                if (y > 0 && forest[x][y - 1] == 'T') {
                                    forest[x][y - 1] = 'F';
                                }
                                if (x < 10 && forest[x + 1][y] == 'T') {
                                    forest[x + 1][y] = 'F';
                                }
                                if (x > 0 && forest[x - 1][y] == 'T') {
                                    forest[x - 1][y] = 'F';
                                }
                            }
                        }
                    }
                    iter++;
                } else {
                    trees = 0;
                    iter = -1;
                }
            } while (trees != 0);
            if(iter != -1){
            iter ++;
            }
            out.write(Integer.toString(iter));
        }

        out.close();
        input.close();
    }

}

