require 'set'

W = 15
H = 19
BLACK = 1
EMPTY = 0
OUT = -1
GOAL = -2

class Board
    def initialize
        @bits = 0
        y_max = 0
        H.times do |i|
            s = gets.chomp
            (0..W-1).each do |j|
                if s[j] == ?O
                    @y = i
                    @x = j
                end
                if s[j] == ?X
                    y_max = i
                end
            end
            s.reverse!
            x = s.gsub(/./) {|c| c == ?X ? ?1 : ?0}.to_i(2)
            @bits += (x << W * i)
        end
        if y_max <= H - 3 && @y <= H - 2
            puts -1
            exit
        end
        @depth = 0
    end

    def jump(dx, dy)
        return unless get(@x+dx, @y+dy) == BLACK
        loop do
            @x += dx
            @y += dy
            break if get(@x, @y) != BLACK
            @bits -= (1 << @y * W + @x)
        end
        @depth += 1
    end

    def get(x, y)
        return OUT if x < 0 or x >= W or y < 0 or y >= H
        return @bits[y * W + x]
    end

    def hash
        (@bits << 10) + (@y << 5) + @x
    end

    def eql?(other)
        hash == other.hash
    end

    def goal?
        @y >= H or (@y == H-1 && @x >= 0 && @x <= W-1)
    end

    def out?
        get(@x, @y) == OUT
    end

    def inspect
        super.inspect + (0..H-1).map {|i| (0..W-1).map {|j| @x == j && @y == i ? ?X : @bits[i*W+j].to_s}.join + "\n"}.join
    end

    attr_reader :depth
end

b = Board.new
queue = [b]
reached = Set[b]

until queue.empty?
    b0 = queue.shift
    [-1, 0, 1].repeated_permutation(2).each do |dx, dy|
        next if dx == 0 && dy == 0
        b = b0.dup
        b.jump(dx, dy)
        next if reached.include?(b)
        if b.goal?
            puts b.depth
            exit
        end
        next if b.out?
        reached << b
        queue << b
    end
end

puts -1