import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) { Kattio io = new Kattio(System.in, System.out); int n = io.getInt(); int size = n*n; int[] dist = new int[size]; boolean[] visited = new boolean[size]; int[][] edges = new int[size][size]; int[][] answer = new int[n][n]; for (int a = 1; a 0 ? 'x' : '.'); // } // io.println(); // } // io.println(); dist[0] = 0; PriorityQueue pq = new PriorityQueue<>( Comparator.comparing(i -> dist[i] < 0 ? Long.MAX_VALUE : dist[i])); pq.add(0); while (!pq.isEmpty()) { int cur = pq.poll(); if (visited[cur]) continue; visited[cur] = true; for (int v2 = 0; v2 < size; v2++) { if (edges[cur][v2] < 0) continue; int d = dist[cur] + edges[cur][v2]; int d2 = dist[v2]; if (d2 < 0 || d < d2) { dist[v2] = d; } pq.add(v2); } } int distab = dist[size-1]; return distab; } private static void addEdge(int n, int[][] edges, int i1, int j1, int i2, int j2) { if (0 <= i2 && i2 < n && 0 <= j2 && j2 < n) { edges[i1*n+j1][i2*n+j2] = 1; } } static class Kattio extends PrintWriter { public Kattio(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int getInt() { return Integer.parseInt(nextToken()); } public double getDouble() { return Double.parseDouble(nextToken()); } public long getLong() { return Long.parseLong(nextToken()); } public String getWord() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } } }