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.util.*;
import java.io.*;

public class codeforces {
	static int n,m;
	static long w;
	static boolean[][]vis;
	static int[][]a;
	static int[]dx=new int[] {1,0,-1,0};
	static int[]dy=new int[] {0,1,0,-1};
	public static boolean valid(long x,long y) {
		return x>-1&&y>-1&&x<n&&y<m&&(!vis[(int) x][(int) y])&&a[(int) x][(int) y]!=-1;
	}
	public static long dfs(int x,int y) {
	vis=new boolean[n][m];
		vis[x][y]=true;
		Queue<pair>q=new LinkedList<pair>();
		Queue<Long>Q=new LinkedList<Long>();
		long min=Long.MAX_VALUE/2;
		q.add(new pair(x, y));
		Q.add(0l);
	
		while (!q.isEmpty()) {
			pair v=q.poll();
			
			long V=Q.poll();
			if(a[(int) v.x][(int) v.y]!=0) {
				min=Math.min(min,V*w+a[(int) v.x][(int) v.y]);
			}
			for(int i=0;i<4;i++) {
				if(valid(v.x+dx[i], v.y+dy[i])) {
//					System.out.println(vis[(int) (v.x+dx[i])][(int) (v.x+dx[i])]);
					vis[(int) (v.x+dx[i])][(int) (v.y+dy[i])]=true;
				
					q.add(new pair(v.x+dx[i], v.y+dy[i]));
					Q.add(V+1);
				}
			}
			
		}
		
		return min;
		

	}
	public static long dfs2(int x,int y) {
		vis=new boolean[n][m];
			vis[x][y]=true;
			Queue<pair>q=new LinkedList<pair>();
			Queue<Integer>Q=new LinkedList<Integer>();
			long min=Long.MAX_VALUE/2;
			q.add(new pair(x, y));
			Q.add(0);
		
			while (!q.isEmpty()) {
				pair v=q.poll();
				int V=Q.poll();
				if(v.x==0&&v.y==0) {
					return V*w;
				}
				for(int i=0;i<4;i++) {
					if(valid(v.x+dx[i], v.y+dy[i])) {
						vis[(int) (v.x+dx[i])][(int) (v.y+dy[i])]=true;
					
						q.add(new pair(v.x+dx[i], v.y+dy[i]));
						Q.add(V+1);
					}
				}
				
			}
			
			return min;
			

		}
	public static void main(String[] args) throws Exception {

		n=sc.nextInt();
		m=sc.nextInt();
		w=sc.nextInt();
		a=new int[n][m];
		vis=new boolean[n][m];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextIntArray(m);
		}
		long a1=dfs(0, 0);
		long a2=dfs(n-1, m-1);
//		pw.println(a1+" "+a2);
		long ans=Long.MAX_VALUE;
		if(a1<Long.MAX_VALUE/4&&a2<Long.MAX_VALUE/4) {
			ans=a1+a2;
		}
		long a3=dfs2(n-1, m-1);
		if(a3<Long.MAX_VALUE/4) {
			ans=Math.min(ans, a3);
		}
		
		pw.println(ans>Long.MAX_VALUE/4?-1:ans);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

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

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public long[] nextlongArray(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public Long[] nextLongArray(int n) throws IOException {
			Long[] a = new Long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

	}

	static class pair implements Comparable<pair> {
		long x;
		long y;

		public pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y) {
					return this.z - other.z;
				}
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static long mod = 1000000007;
	static Random rn = new Random();
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);
}