Shortest path in the a Maze

Background:

The Maize Maze is a maze made completely out of corn. The designers of the maze allow people to run through the maze and very promptly get lost. They would, however, like to know how long the shortest path through the maze is. That's your job.

Input:

There will be one test case that consists of one maze. Each line of input will describe one row of the maze. There will no more than 80 columns and no more than 80 rows. The given maze will always be rectangular, though, not necessarily a square.

Each position of the maze is one of two characters. A `O' means you may move onto that position. A `X' means that space is occupied by a wall.

You are allowed to move in any direction (up, down, left, right, diagonal) provided that the square you move into isn't an `X'.

You always start in the upper left hand corner of the maze. The exit is always at the lower right hand corner of the maze. There will always be at least one path through the maze.

Output:

The output is the shortest number of squares you must step in to complete the maze.

Sample Input:

OXXXOOXXX
OOXXXOOXX
OOXXXXOXX
OXXXXXOXO
OOXXXXOXO
XOOOOOOOO
XOXXXXXOO

Sample Output:

12