import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}
const H = 19;
const W = 15;
const INF = int.max / 2;

void main() {
    auto F = new string[19];
    foreach (ref L; F) L = readln.chomp;
    int sy, sx;
    void find_init_pos() {
        foreach (i; 0 .. H) {
            foreach (j; 0 .. W) {
                if (F[i][j] == 'O') {
                    sy = i;
                    sx = j;
                    return;
                }
            }
        }
    }
    find_init_pos();

    if (! (F[H - 2].any!((c) => c == 'X') || F[H - 1].any!((c) => c == 'X'))) {
        writeln(-1);
        return;
    }

    bool[W][H] used;
    bool dfs(int cy, int cx, int d) {
        if (d == 0) return false;
        //log([cy, cx, t, d]);
        for (int dy = -1; dy <= 1; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
                if (dy == 0 && dx == 0) continue;
                int y = cy + dy, x = cx + dx;
                if (! (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x])) continue;
                while (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x]) {
                    y += dy;
                    x += dx;
                }
                if (y == H - 1 && 0 <= x && x < W) return true;
                if (y >= H) return true;
                if (x < 0 || x >= W) continue;
                y = cy + dy, x = cx + dx;
                while (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x]) {
                    used[y][x] = true;
                    y += dy;
                    x += dx;
                }
                if (dfs(y, x, d - 1)) return true;
                y -= dy, x -= dx;
                while (y != cy || x != cx) {
                    used[y][x] = false;
                    y -= dy;
                    x -= dx;
                }
            }
        }
        return false;
    }

    for (int d = 1; d <= 20; d++) {
        if (dfs(sy, sx, d)) {
            writeln(d);
            return;
        }
    }
    writeln(-1);

}