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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
 

public class Fourth
{
    public static void main(String[] args) throws Exception
    {
        int n = i();
        int m=i();
        int p=i();
        ArrayList<Node>[] al = new ArrayList[p+1];
        for( int i=0 ; i<=p ; i++ )
        	al[i]=new ArrayList();
        for( int i=0 ; i<n ; i++ )
        {
        	for( int j=0 ; j<m ; j++ )
        	{
        		Node nn = new Node(i,j,i());
        		al[nn.p].add(nn);
        	}
        }
        
        long dpl[][] = new long[n][m];
        long pre[][] = new long[n][m];
        long suff[][] = new long[n][m];
        boolean[] fl=  new boolean[n];
        boolean[] fc=  new boolean[n];
        for( int i=0 ; i<n ; i++ )
        {
        	Arrays.fill(dpl[i], Long.MAX_VALUE/2);
        }
        for( Node nn : al[1] )
    	{
        	dpl[nn.r][nn.c]=nn.r+nn.c;
        	fl[nn.r]=true;
    	}
        for( int i=0 ; i<n ; i++ )
        {
        	if( !fl[i] ) continue;
        	for( int j=0 ; j<m ; j++ )
            {
        		pre[i][j] = dpl[i][j]+m-1-j;
        		suff[i][j] = dpl[i][j]+j;
            }
        	for( int j=1 ; j<m ; j++ )
            {
        		
        		pre[i][j] = Math.min(pre[i][j], pre[i][j-1]);
            }
        	for( int j=m-2 ; j>=0 ; j-- )
            {
        		suff[i][j] = Math.min(suff[i][j], suff[i][j+1]);
            }
        }
        
        
        for( int i=1 ; i<=p ; i++ )
        {
        	for( int kk=0 ; kk<n ; kk++ )
            {
        		if( !fl[kk] ) continue;
            	Arrays.fill(dpl[kk], Long.MAX_VALUE/2);
            }
        	for( Node nn : al[i] )
        	{
        		int c=nn.c,r=nn.r;
        		fc[r]=true;
        		for( int j=0 ; j<n ; j++ )
        		{
        			if( !fl[j] ) continue;
        			dpl[r][c] = Math.min(Math.min(suff[j][c]-c+abs(j-r), pre[j][c]-(m-1-c)+abs(j-r) ), dpl[r][c]);
        		}
        	}
        	
        	 for( int kk=0 ; kk<n ; kk++ )
             {
        		 if( !fc[kk] ) continue;
             	for( int l=0 ; l<m ; l++ )
                 {
             		pre[kk][l] = dpl[kk][l]+m-1-l;
             		suff[kk][l] = dpl[kk][l]+l;
                 }
             	for( int j=1 ; j<m ; j++ )
                 {
             		pre[kk][j] = Math.min(pre[kk][j], pre[kk][j-1]);
                 }
             	for( int j=m-2 ; j>=0 ; j-- )
                 {
             		suff[kk][j] = Math.min(suff[kk][j], suff[kk][j+1]);
                 }
             }
        	
        	 fl=fc;
        	 fc=new boolean[n];
        	
        }
        
        out.println(dpl[al[p].get(0).r][al[p].get(0).c]);
        
        out.close();
        
    }
    
    static long abs( long a )
    {
    	return a>0?a:-a;
    }
 
 	static class Node implements Comparable<Node>
 	{
 		int dis, r,c,p;
 		
 		public Node( int rr, int cc, int pp )
 		{
 			r=rr; c=cc; p=pp;
 		}

		@Override
		public int compareTo(Node o) 
		{
			if( o.dis<this.dis ) return 1;
			if( o.dis>this.dis ) return -1;
			// TODO Auto-generated method stub
			return 0;
		}
 		
 	}
 	
    static InputReader in = new InputReader(System.in);
    static OutputWriter out = new OutputWriter(System.out);
    
    static int i()
    {
    	return in.readInt();
    }
    
    static long l()
    {
    	return in.readLong();
    }
    
    static double d()
    {
    	return in.readDouble();
    }
    
    static String s()
    {
    	return in.readString();
    }
    
    static void Iarr( int[] array, int no )
    {
    	for( int i=0 ; i<no ; i++ )
    	{
    		array[i] = i(); 
    	}
    }
    
    static void Larr( long[] array, int no )
    {
    	for( int i=0 ; i<no ; i++ )
    	{
    		array[i] = l(); 
    	}
    }
    
    static void Darr( double[] array, int no )
    {
    	for( int i=0 ; i<no ; i++ )
    	{
    		array[i] = d(); 
    	}
    }
    
    static void Sarr( String[] array, int no )
    {
    	for( int i=0 ; i<no ; i++ )
    	{
    		array[i] = s(); 
    	}
    }
    
    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
 
        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
 
        
        
        
        
        
        
        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
 
        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        public String next()
        {
            return readString();
        }
 
        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
 
    private static class OutputWriter
    {
        private final PrintWriter writer;
 
        public OutputWriter(OutputStream outputStream)
        {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }
 
        public OutputWriter(Writer writer)
        {
            this.writer = new PrintWriter(writer);
        }
 
        public void print(Object... objects)
        {
            for (int i = 0; i < objects.length; i++)
            {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }
 
        public void println(Object... objects)
        {
            print(objects);
            writer.println();
        }
 
        public void close()
        {
            writer.close();
        }
 
        public void flush()
        {
            writer.flush();
        }
     }
}