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.util.*;
import java.io.*;
public class D677 {
	public static void main(String[] args) throws IOException{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		try {
			inputStream = new FileInputStream("input.inp");
//			outputStream = new FileOutputStream("output.out");
		} catch (IOException e) {
			inputStream = System.in;
			outputStream = System.out;
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}
	static final int N = 1005;
	static final int oo = 1000000007;
	static final double pi = Math.acos(-1);
	
	static class Task {
		public void solve(InputReader in, PrintWriter out) {
			int m = in.nextInt(), n = in.nextInt(), p = in.nextInt();
			int[][] a = new int[N][N], f = new int[N][N];
			ArrayList<pair>[] color = new ArrayList[N*N];
			for(int i=1; i<=p; ++i) color[i] = new ArrayList<pair>();
			for(int i=1; i<=m; ++i) for(int j=1; j<=n; ++j) {
				a[i][j] = in.nextInt();
				if (a[i][j] == 1) f[i][j] = i+j-2;
				else f[i][j] = oo;
				color[a[i][j]].add(new pair(i,j));
			}
			for(int k = 1; k<p; ++k) {
				boolean[] exist = new boolean[N];
				if (color[k] != null)
				for(int i=0; i<color[k].size(); ++i) {
					pair pr = (pair) color[k].get(i);
//					int x = pr.F, y = pr.S;
					exist[pr.F] = true;
				}
				ArrayList<Integer>[] col = new ArrayList[N];
				for(int j=1; j<=n; ++j) col[j] = new ArrayList<Integer>(0);
				if (color[k+1] != null)
				for(int i=0; i<color[k+1].size(); ++i) {
					pair pr = (pair) color[k+1].get(i);
					col[pr.S].add(pr.F);
				}
				for(int i=1; i<=m; ++i) if (exist[i]) {
					int best = oo;
					for(int j=1; j<=n; ++j) {
						++best;
						if (a[i][j] == k) best = Math.min(best, f[i][j]); 
						if (color[k+1] != null) 
						for(int l=0; l<col[j].size(); ++l) {
							int x = col[j].get(l);
							f[x][j] = Math.min(f[x][j], best+Math.abs(x-i));
						}
					}
					best = oo;
					for(int j=n; j>=1; --j) {
						++best;
						if (a[i][j] == k) best = Math.min(best, f[i][j]); 
						if (col[j] != null) 
						for(int l=0; l<col[j].size(); ++l) {
							int x = col[j].get(l);
							f[x][j] = Math.min(f[x][j], best+Math.abs(x-i));
						}
					}
					
				}
			}
			for(int i=1; i<=m; ++i) for(int j=1; j<=n; ++j) 
				if (a[i][j] == p) out.println(f[i][j]);
		}
		
		public int getDist(int x, int y, int u, int v) {
			return Math.abs(x-u) + Math.abs(y-v);
		}
		
		static class pair {
			int F, S;
			pair(int F, int S) {
				this.F = F;
				this.S = S;
			}
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public char nextChar() {
			return next().charAt(0);
		}
	}
}
