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();

    bool[W][H] used;
    bool dfs(int cy, int cx, int t, int d) {
        if (t == d) 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;
                auto backup = used;
                scope(exit) used = backup;
                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]) {
                    used[y][x] = true;
                    y += dy;
                    x += dx;
                }
                if (y >= H - 1) {
                    return true;
                }
                if (x < 0 || x >= W) continue;
                if (dfs(y, x, t + 1, d)) return true;
            }
        }
        return false;
    }

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

}