#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){

    const int h = 19, w = 15;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)
        cin >> s[i];
    vector<vector<char>> v(h, vector<char>(w, -1));
    int st = 0, en = 0;
    int cnt = 0;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j){
            if(s[i][j] == 'O')
                st = i, en = j;
            if(s[i][j] == 'X'){
                v[i][j] = cnt++;
            }
        }

    vector<int> dx{-1, 0, 1, 1, 1, 0, -1, -1};
    vector<int> dy{1, 1, 1, 0, -1, -1, -1, 0};

    vector<map<pair<int,int>, int>> dp(1 << cnt);
    char ans = 100;
    dp[0][make_pair(st, en)] = 0;
    for(int mask = 0; mask < (1 << cnt); ++mask){
        for(auto& p : dp[mask]){
            int i, j;
            tie(i, j) = p.first;
            int val = p.second;
            for(int d = 0; d < 8; ++d){
                int ma = 0;
                bool fl = true;
                int dist = 1;
                int nx, ny;
                for(;; ++dist){
                    nx = i + dist * dx[d];
                    ny = j + dist * dy[d];
                    if(nx >= h)
                        break;
                    if(nx < 0 || ny < 0 || ny >= w){
                        fl = false;
                        break;
                    }
                    if(v[nx][ny] == -1 || mask & (1 << v[nx][ny]))
                        break;
                    ma |= (1 << v[nx][ny]);
                }
                if(!fl || dist == 1)
                    continue;
                if(nx >= h - 1){
                    chmin(ans, char(val + 1));
                    continue;
                }
                if(dp[mask | ma].find(make_pair(nx, ny)) == dp[mask | ma].end() || dp[mask | ma][make_pair(nx, ny)] > char(val + 1)){
                    dp[mask | ma][make_pair(nx, ny)] = char(val + 1);
                }
            }
        }
    }
    cout << (ans == 100 ? -1 : ans) << endl;

    return false;
}

signed main(){
    while(solve());
}

