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>
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert 
#define mp make_pair
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define ft front() 
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

#ifndef ONLINE_JUDGE
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl;
#else
#define deb(x)
#endif

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18; 
const ld pie = acos((ld)-1);

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void __print(int x) {cerr<<x;}
void __print(char x) {cerr<<x;}
void __print(string x) {cerr<<x;}
void __print(float x) {cerr<<x;}
void __print(double x) {cerr<<x;}
void __print(bool x) {cerr<<x;}
void __print(ll x) {cerr<<x;}

template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

int n,m;

vector<vector<ll>> gridBfs(vector<vector<ll>> arr, int X, int Y) {

	vector<vector<ll>> dis(n, vector<ll>(m,0));
	rep(i,0,n) rep(j,0,m) dis[i][j] = inf;

	dis[X][Y] = 0;
	queue<pair<int,int>> q;
	q.push({X,Y});

	auto isValid = [&](int x, int y) -> bool {

		if(x < n && y < m && x >= 0 && y >= 0 && arr[x][y]!=-1) {
			return 1;
		}

		return 0;
	};

	while(!q.empty()) {
		pair<int,int> cell = q.ft;
		q.pop();
		
		for(int i=0;i<4;++i) {
			int newX = cell.ff + dx[i];
			int newY = cell.ss + dy[i];

			if(isValid(newX, newY) && dis[newX][newY] == inf) {
				dis[newX][newY] = dis[cell.ff][cell.ss] + 1;
				q.push({newX, newY});
			}
		}
	}

	rep(i,0,n) {
		deb(dis[i]);
	}

	return dis;
}

void solve() {

	ll w;
	scanf("%d%d%lld",&n,&m,&w);

	vector<vector<ll>> arr(n, vector<ll>(m,0));

	rep(i,0,n) rep(j,0,m) scanf("%lld",&arr[i][j]);

	vector<vector<ll>> dis1 = gridBfs(arr,0,0);
	vector<vector<ll>> dis2 = gridBfs(arr,n-1,m-1);

	ll ans = 1e18;

	if(dis1[n-1][m-1]!=inf) {
		ans = min(ans, dis1[n-1][m-1]*w);
	}

	ll ans1 = 1e18;
	ll ans2 = 1e18;

	rep(i,0,n) {
		rep(j,0,m) {
			if(dis1[i][j]!=inf&&arr[i][j]>0) {
				ans1 = min(ans1, arr[i][j] + dis1[i][j]*w);
			}
		}	
	}

	rep(i,0,n) {
		rep(j,0,m) {
			if(dis2[i][j]!=inf&&arr[i][j]>0) {
				ans2 = min(ans2, arr[i][j] + dis2[i][j]*w);
			}
		}	
	}

	ans = min(ans, ans1 + ans2);

	if(ans >= 1e18) {
		puts("-1");
		return ;
	}

	printf("%lld\n",ans);

	return;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("error.txt", "w", stderr);
#endif

	auto start = std::chrono::high_resolution_clock::now();

	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) solve();

  auto stop = std::chrono::high_resolution_clock::now(); 
  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< endl;


  /*STUFF TO LOOK:	
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/  

	return 0;
}

