Path caver
The cave is represented by a cube, partitioned into N parts of each imereniyu (ie N^3 cubic cells). Each cell is either empty or completely filled with stone. Based on the provisions spaleologa in a cave, you want to find a minimum number of movements of cells it takes to get to the surface. Move from cell to cell is possible only if they are both free and have a common face.
Input
The first line contains the number N (1 ≤ N ≤ 30). This is followed by N blocks. The unit consists of empty rows and N lines of N characters: # denotes a cage filled with rocks, point - a free cell. Initial position of the caver indicated by a capital letter S. The first block represents the top level of the cave, the achievement of any free his cell means going to the surface. The yield on the surface is always possible.
Output
Derive a single number - the length of the path to the surface.