#include<iostream>
#include<map>
#include<algorithm>
#include<queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> P2;

const int dy[] = {-1,-1,0,1,1,1,0,-1}, dx[] = {0,1,1,1,0,-1,-1,-1};
int sy,sx;
string b[20];
map<P,int> stone;

string bin(int x){
  string res;
  for(int i=0;i<20;i++){
    if(x&1)res += "1";
    else res += "0";
    x/=2;
  }
  return res;
}

int main(){
  for(int i=0;i<19;i++)cin >> b[i];

  int cnt = 0;
  for(int i=0;i<19;i++){
    for(int j=0;j<15;j++){
      if(b[i][j] == 'O'){sy = i; sx = j;}
      if(b[i][j] == 'X'){
	stone[P(i,j)] = cnt++;
      }
    }
  }

  P2 cur = P2(P(sy,sx),0);
  map<P2,int> d;
  d[cur] = 0;
  queue<P2> q;
  q.push(cur);

  int res = -1;
  while(q.size()){
    cur = q.front(); q.pop();
    int state = cur.sc;

    for(int i=0;i<8;i++){
      int ny = cur.fs.fs+dy[i], nx = cur.fs.sc+dx[i];
      int nstate = state;

      if(ny<0 || nx<0 || ny>=19 || nx>=15)continue;
      while(b[ny][nx] == 'X'){
	int id = stone[P(ny,nx)];

	if((nstate>>id)&1)break;

	nstate |= 1<<id;
        ny = ny+dy[i], nx = nx+dx[i];

	if(ny<0 || nx<0 || ny>=19 || nx>=15)break;
      }
      if(ny==cur.fs.fs+dy[i] && nx==cur.fs.sc+dx[i])continue;

      if(ny>=19){
	res = d[cur]+1;
	goto END;
      }
      
      if(ny<0 || nx<0 || nx>=15)continue;
      if(ny>=18){
	res = d[cur]+1;
	goto END;
      }

      P2 nxt = P2(P(ny,nx),nstate);
      if(d.find(nxt) == d.end()){
	q.push(nxt);
	d[nxt] = d[cur]+1;
      }
    }
  }
 END: cout << res << endl;
}