Dima overslept the alarm clock, which was supposed to raise him to school.

Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school.

The city where Dima lives is a rectangular field of n × m size. Each cell (i, j) on this field is denoted by one number a_{ij}:

  * The number -1 means that the passage through the cell is prohibited; 
  * The number 0 means that the cell is free and Dima can walk though it. 
  * The number x (1 ≤ x ≤ 10^9) means that the cell contains a portal with a cost of x. A cell with a portal is also considered free. 



From any portal, Dima can go to any other portal, while the time of moving from the portal (i, j) to the portal (x, y) corresponds to the sum of their costs a_{ij} + a_{xy}.

In addition to moving between portals, Dima can also move between unoccupied cells adjacent to one side in time w. In particular, he can enter a cell with a portal and not use it.

Initially, Dima is in the upper-left cell (1, 1), and the school is in the lower right cell (n, m).

Input

The first line contains three integers n, m and w (2 ≤ n, m ≤ 2 ⋅ 10^3, 1 ≤ w ≤ 10^9), where n and m are city size, w is time during which Dima moves between unoccupied cells.

The next n lines each contain m numbers (-1 ≤ a_{ij} ≤ 10^9) — descriptions of cells.

It is guaranteed that the cells (1, 1) and (n, m) are free.

Output

Output the minimum time it will take for Dima to get to school. If he cannot get to school at all, then output "-1".

Example

Input


5 5 1
0 -1 0 1 -1
0 20 0 0 -1
-1 -1 -1 -1 -1
3 0 0 0 0
-1 0 0 0 0


Output


14

Note

Explanation for the first sample: 

<image>

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class N719 {
	static PrintWriter out;
	static Scanner sc;
	static ArrayList<Integer>q,w;
	static ArrayList<Integer>adj[];
	static HashSet<Integer>primesH;
	static boolean prime[];
	//static ArrayList<Integer>a;
	static HashSet<Long>tmp;
	static boolean[]v;
	static int[]c,d;
	static int[][]dp;
	static char[][]mp;
	static int A,B,n,m,h,ans;
	static String a,b;
	public static void main(String[]args) throws IOException {
		sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		//A();
		//B();
	    //C();
	   // D();
		//E();
		//F1();
		G();
		out.close();
	}
	  private static void A() throws IOException {
		  	int t=ni();
			while(t-->0) {
				int n=ni();
				String s=ns();
				int[]occ=new int[27];
				boolean ok=true;
				for(int i=0;i<n-1;i++) {
					while(i<n-1&&s.charAt(i)==s.charAt(i+1))i++;
					if(occ[s.charAt(i)-'A']!=0) {
						ok=false;
						break;
					}
					occ[s.charAt(i)-'A']++;
				}
				if(n!=1&&occ[s.charAt(n-1)-'A']!=0&&s.charAt(n-1)!=s.charAt(n-2))ok=false;
				out.println(ok?"YES":"NO");
			}
		
	   }
		static void B() throws IOException {
			int t=ni();
			while(t-->0) {
				int n=ni();
				int ans=0;
				int cur=1;
				while(cur<=n) {
					int tmp=cur;int i=0;
					while(tmp<=n&&i<9) {
						ans++;
						tmp+=cur;
						i++;
					}
					cur=10*cur+1;
				}
				ol(ans);
			}
		}
		
		static void C() throws IOException{
			 int t=ni();
			 while(t-->0) {
				 int n=ni();
				 int[][]ans=new int[n][n];
				 if(n==1) {ol(1);continue;
				 
				 }
				 if(n==2) {ol(-1);continue;
				 
				 }
				 for(int i=0;i<n;i++) {
					 ans[n-1-i][i]=i+1;
				 }
				 int num=n+1;
				 for(int i=n-2,elems=n-1;elems>=1;elems--,i--) {
					
					 for(int cnt=0;cnt<elems;cnt++) {
						 ans[i-cnt][cnt]=num++;
					 }
					 num+=elems;
				 }
				 num=2*n;
				 for(int j=1,elems=n-1;elems>=1;elems--,j++) {
					 for(int cnt=0;cnt<elems;cnt++) {
						 ans[n-1-cnt][j+cnt]=num++;
					 }
					 num+=elems-1;
				 }
				 for(int i=0;i<n;i++) {
					 for(int j=0;j<n;j++) {
						 out.print(ans[i][j]+" ");
					 }
					 ol("");
				 }
			 }
		}
	static void D() throws IOException {
		int t=ni();
		while(t-->0) {
			int n=ni();
			int[]a=nai(n);
			int[]occ=new int[2*n+1];
			long ans=0l;
			for(int i=0;i<n;i++) {
				a[i]-=i;
				a[i]+=n;
				occ[a[i]]++;
			}
			for(int i=0;i<occ.length;i++) {
				ans+=(long)(occ[i]*1l*(occ[i]-1))/2l;
			}
			ol(""+ans);
		}
		
	}
	static void E() throws IOException {
		int t=ni();
		while(t-->0) {
			int n=ni();
			String s=ns();
			long[]suff=new long[n],pre=new long[n];
			long cnt=s.charAt(0)=='.'?0l:1l;
			for(int i=1;i<n;i++) {
				if(s.charAt(i)=='*') {
					cnt++;
					pre[i]=pre[i-1];
				}else {
					pre[i]=pre[i-1]+cnt;
				}
			}
			cnt=s.charAt(n-1)=='.'?0l:1l;
			for(int i=n-2;i>=0;i--) {
				if(s.charAt(i)=='*') {
					cnt++;
					suff[i]=suff[i+1];
				}else {
					suff[i]=suff[i+1]+cnt;
				}
			}
			long mn=Long.MAX_VALUE;
			for(int i=1;i<n;i++) {
				mn=Math.min(mn, pre[i-1]+suff[i]);
			}
			if(n==1) {
				ol(0);continue;
			}
//			out.println(Arrays.toString(pre));
//			out.println(Arrays.toString(suff));
			ol(""+mn);
		}
	}
	static void F1() throws IOException {
		int n=ni(),t=ni(),k=ni();
		int l=1,r=n;
		while(l<r-1) {
			int mid=(l+r)/2;
			int elems=mid-l+1;
			ol("? "+l+" "+mid);
			out.flush();
			int sum=ni();
			int zeros=elems-sum;
			if(zeros>=k) {
				r=mid;
			}else {
				k-=zeros;
				l=mid+1;
			}
		}
		ol("? "+l+" "+l);
		out.flush();
		int sum=ni();
		if(sum==1||k==2)l++;
		ol("! "+l);
	}
	static void F2() throws IOException {
		int n=ni(),t=ni(),k=ni();
		
	}
	static long [][]d1,d2,map;
	static long W;
	static int []dx=new int[] {0,1,-1,0};
	static int []dy=new int[] {1,0,0,-1};
	static void G() throws IOException {
		n=ni();
		m=ni();
		W=nl();
		map=nml(n,m);
		long oo=(long)1e18;
		d1=new long[n][m];d2=new long[n][m];
		bfs(0,0,d1);
		bfs(n-1,m-1,d2);
		ArrayList<int[]>ports=new ArrayList<int[]>();
		long bestP=oo;
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(map[i][j]>=1&&d1[i][j]!=-1) {
					bestP=Math.min(bestP,d1[i][j]*W+map[i][j]);
				}
			}
		}
		long ans=d1[n-1][m-1]*W;
		if(d1[n-1][m-1]==-1)ans=oo;
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(map[i][j]>=1&&d2[i][j]!=-1) {
				ans=Math.min(ans, bestP+d2[i][j]*W+map[i][j]);
				}
			}
		}
		
		out.println(ans>=oo?-1:ans);
	}
	private static void bfs(int i, int j,long[][]d) {
		d[i][j]=1;
		int[]q=new int[2*n*m];
		int e=0,s=0;
		q[e++]=i;q[e++]=j;
		while(s<e) {
			int x=q[s++],y=q[s++];
			for(int a=0;a<4;a++) {
				int nx=x+dx[a],ny=y+dy[a];
				if(nx>=0&&nx<n&&ny>=0&&ny<m&&d[nx][ny]==0&&map[nx][ny]!=-1) {
					q[e++]=nx;q[e++]=ny;
					d[nx][ny]=d[x][y]+1;
				}
			}
		}
		for(int a=0;a<d.length;a++)
			for(int b=0;b<d[0].length;b++)
				d[a][b]--;
		
	}
	static int ni() throws IOException {
		return sc.nextInt();
	}
	static double nd() throws IOException {
		return sc.nextDouble();
	}
	static long nl() throws IOException {
		return  sc.nextLong();
	}
	static String ns() throws IOException {
		return sc.next();
	}
	static int[] nai(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		return a;
	}
	static long[] nal(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		return a;
	}
	static int[][] nmi(int n,int m) throws IOException{
		int[][]a=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		return a;
	}

	static long[][] nml(int n,int m) throws IOException{
		long[][]a=new long[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextLong();
			}
		}
		return a;
	}
	static void o(String x) {
		out.print(x);
	}
	static void ol(String x) {
		out.println(x);
	}
	static void ol(int x) {
		out.println(x);
	}
	static void disp1(int []a) {
		for(int i=0;i<a.length;i++) {
			out.print(a[i]+" ");
		}
		out.println();
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public boolean hasNext() {return st.hasMoreTokens();}
		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());}

		public String nextLine() throws IOException {return br.readLine();}
			
		public boolean ready() throws IOException {return br.ready(); }
		

	}
}
