// Arup Guha
// 2/25/2017
// Solution to 2017 January USACO Gold Problem: Cow Navigation

import java.util.*;
import java.io.*;

public class cownav {

	// How we can move.
	final public static int[] DX = {0,1,0,-1};
	final public static int[] DY = {1,0,-1,0};

	public static int n;
	public static boolean[][] grid;

	public static void main(String[] args) throws Exception {

		// Read input.
		Scanner stdin = new Scanner(new File("cownav.in"));
		n = stdin.nextInt();
		grid = new boolean[n][n];

		// Store grid as booleans.
		for (int i=n-1; i>=0; i--) {
			String s = stdin.next();
			for (int j=0; j<n; j++)
				grid[i][j] = s.charAt(j) == 'E';
		}

		// Output the result.
		PrintWriter out = new PrintWriter(new FileWriter("cownav.out"));
		out.println(bfs());

		out.close();
		stdin.close();
	}

	public static int bfs() {

		// Set up BFS.
		LinkedList<Integer> q = new LinkedList<Integer>();
		HashMap<Integer,Integer> dist = new HashMap<Integer,Integer>();
		q.offer(1);
		dist.put(1, 0);

		// Storage is (x, y, dir), (x, y, dir) for two possible positions/directions.
		// 0 is right, 1 is down, 2 is left, 3 is up. "Mask" with 6 pieces, size of
		// each piece is n, n, 4, n, n, 4. I have flipped the board from top right to bottom left.

		// Just run like regular BFS.
		while (q.size() > 0) {

			int next = q.poll();
			int steps = dist.get(next);

			// Check if we're done!
			if (done(next)) return steps;

			// Extract out the two pieces.
			int left = next/(4*n*n);
			int right = next%(4*n*n);

			// Try each of the three directions.
			for (int i=0; i<3; i++) {

				// Form new state with direction i.
				int nextL = next(left, i);
				int nextR = next(right, i);
				int mask = 4*n*n*nextL + nextR;
			//	System.out.println("  -- "+nextL+" "+nextR);

				// Been here, skip it.
				if (dist.containsKey(mask)) continue;

				// Update distance to here, and put this new mask in the queue.
				dist.put(mask, steps+1);
				q.offer(mask);
			}

		}

		// Should never get here.
		return -1;

	}

	// Returns next position if current state is cur, and move is dir.
	// dir = 0 is forward, dir = 1 is left, dir = 2 is right.
	public static int next(int cur, int dir) {

		// Just extract stuff.
		int myDir = cur%4;
		int rest = cur/4;
		int myX = rest/n;
		int myY = rest%n;

		// At goal, ignore further commands.
		if (myX == n-1 && myY == n-1) return cur;

		// Might get stuck moving.
		if (dir == 0) {

			if (inbounds( myX+DX[myDir], myY+DY[myDir]) && grid[myX+DX[myDir]][myY+DY[myDir]])
				return 4*n*(myX+DX[myDir]) + 4*(myY+DY[myDir]) + myDir;
			else
				return cur;
		}

		// Rotate left.
		else if (dir == 1) {
			myDir = (myDir+3)%4;
			return 4*rest + myDir;
		}

		// Rotate right.
		else {
			myDir = (myDir + 1)%4;
			return 4*rest + myDir;
		}
	}

	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < n;
	}

	public static boolean done(int mask) {

		// Get masks of both positions.
		int left = mask/(4*n*n);
		int right = mask%(4*n*n);

		// Just get the positions w/o direction.
		int lPos = left/4;
		int rPos = right/4;

		return lPos == n*n-1 && rPos == n*n-1;
	}

}