Vanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x ≤ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.

Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.

Input

The first line of the input contains three integers n, m and p (1 ≤ n, m ≤ 300, 1 ≤ p ≤ n·m) — the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.

Each of the following n lines contains m integers aij (1 ≤ aij ≤ p) — the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.

Output

Print one integer — the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.

Examples

Input

3 4 3
2 1 1 1
1 1 1 1
2 1 1 3


Output

5


Input

3 3 9
1 3 5
8 9 7
4 6 2


Output

22


Input

3 4 12
1 2 3 4
8 7 6 5
9 10 11 12


Output

11
import java.io.*;
import java.util.*;

public class D {
    @SuppressWarnings("unchecked")
    public static void solution(BufferedReader reader, PrintWriter out)
            throws IOException {
        In in = new In(reader);
        int n = in.nextInt(), m = in.nextInt(), p = in.nextInt();
        ArrayList<Cell>[] loc = new ArrayList[p + 1];
        for (int i = 1; i <= p; i++)
            loc[i] = new ArrayList<Cell>();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                int a = in.nextInt();
                loc[a].add(new Cell(i, j));
            }

        int[][] dp = new int[n][m];
        for (int i = 0; i < n; i++)
            Arrays.fill(dp[i], Integer.MAX_VALUE);

        for (Cell c : loc[1])
            dp[c.i][c.j] = c.i + c.j;
        int[] ii = new int[] { 0, -1, 0, 1 };
        int[] jj = new int[] { -1, 0, 1, 0 };

        for (int cur = 1; cur < p; cur++) {
            int next = cur + 1;
            if (loc[cur].size() * loc[next].size() <= 2000000)
                for (Cell c1 : loc[cur])
                    for (Cell c2 : loc[next]) {
                        int d = dp[c1.i][c1.j] + Math.abs(c1.i - c2.i)
                                + Math.abs(c1.j - c2.j);
                        dp[c2.i][c2.j] = Math.min(dp[c2.i][c2.j], d);
                    }
            else {
                int[][] d = new int[n][m];
                for (int i = 0; i < n; i++)
                    Arrays.fill(d[i], Integer.MAX_VALUE);
                PriorityQueue<State> queue = new PriorityQueue<State>();
                for (Cell c : loc[cur]) {
                    queue.add(new State(dp[c.i][c.j], c.i, c.j));
                    d[c.i][c.j] = dp[c.i][c.j];
                }
                while (!queue.isEmpty()) {
                    State s = queue.remove();
                    for (int i = 0; i < 4; i++) {
                        int x = s.i + ii[i], y = s.j + jj[i];
                        if (x < 0 || x >= n || y < 0 || y >= m)
                            continue;
                        if (d[s.i][s.j] + 1 < d[x][y]) {
                            d[x][y] = d[s.i][s.j] + 1;
                            queue.add(new State(d[x][y], x, y));
                        }
                    }
                }
                for (Cell c : loc[next])
                    dp[c.i][c.j] = d[c.i][c.j];
            }
        }

        Cell c = loc[p].get(0);
        out.println(dp[c.i][c.j]);
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(
                new BufferedWriter(new OutputStreamWriter(System.out)));
        solution(reader, out);
        out.close();
    }

    protected static class In {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public In(BufferedReader reader) {
            this.reader = reader;
        }

        public String next() throws IOException {
            while (!tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    protected static class Cell {
        int i, j;

        public Cell(int i, int j) {
            super();
            this.i = i;
            this.j = j;
        }

    }

    protected static class State implements Comparable<State> {
        int d, i, j;

        public State(int d, int i, int j) {
            this.d = d;
            this.i = i;
            this.j = j;
        }

        @Override
        public int compareTo(State s) {
            return Integer.compare(d, s.d);
        }
    }
}