import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class No3558 { public static String[][] str; public static void main(String[] args) throws IOException{ String[] strings = readStr(); int n = Integer.parseInt(strings[0]); str = new String[strings.length-1][strings[1].length()]; for(int i = 1;i < strings.length;i++) { str[i-1] = strings[i].split(""); } int[] lxy = new int[2], rxy = new int[2] ; int count = 0; lxy = getXY("#"); rxy = getXY("."); while(!check(lxy, rxy)) { count += Math.abs(rxy[0] - lxy[0]) + Math.abs(rxy[1] - lxy[1]); str[lxy[1]][lxy[0]] = "."; str[rxy[1]][rxy[0]] = "#"; lxy = getXY("#"); rxy = getXY("."); } System.out.println(count); } public static boolean check(int[] lxy,int[] rxy) { boolean result = false; if(lxy[0] == -1 && lxy[1] == -1 && rxy[0] == -1 && rxy[1] == -1) { result = true; } return result; } public static int[] getXY(String bw) { int[] resultXY = {-1 , -1}; boolean flg = false; int sx = 0; if(".".equals(bw)) { sx = str.length; } for(int y = 0;y < str.length;y++) { for(int x = sx;x < str.length + sx;x++) { if(bw.equals(str[y][x])) { resultXY[0] = x; resultXY[1] = y; flg = true; break; } } if(flg) { break; } } return resultXY; } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }