//https://u...content-available-to-author-only...o.org/index.php?page=viewproblem2&cpid=717
#include<bits/stdc++.h>
#define int long long
using namespace std;
void usaco(){
freopen("visitfj.in","r",stdin);
freopen("visitfj.out","w",stdout);
}
int n,t,mx[]={1,-1,0,0},my[]={0,0,1,-1};
bool check(int x,int y){
if(x<0||y<0||x>=n||y>=n) return false;
return true;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
usaco();
cin>>n>>t;
int a[n][n],dis[n][n][3];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
dis[i][j][0]=dis[i][j][1]=dis[i][j][2]=1e18;
}
}
// cost n x y
priority_queue<tuple<int,int,int,int>>q;
q.push({0,0,0,0}); dis[0][0][0]=0;
while(!q.empty()){
auto [cost,m,x,y]=q.top(); q.pop();
int g=(m+1)%3;
cost=-cost;
if(cost>dis[x][y][m]) continue;
for(int i=0;i<4;i++){
if(check(x+mx[i],y+my[i])){
if(dis[x+mx[i]][y+my[i]][g]>cost+(g?0:a[x+mx[i]][y+my[i]])+t){
dis[x+mx[i]][y+my[i]][g]=cost+(g?0:a[x+mx[i]][y+my[i]])+t;
q.push({-dis[x+mx[i]][y+my[i]][g],g,x+mx[i],y+my[i]});
}
}
}
}
cout<<min({dis[n-1][n-1][0],dis[n-1][n-1][1],dis[n-1][n-1][2]});
}
Ly9odHRwczovL3UuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLm8ub3JnL2luZGV4LnBocD9wYWdlPXZpZXdwcm9ibGVtMiZjcGlkPTcxNwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIGludCBsb25nIGxvbmcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCB1c2FjbygpewoJZnJlb3BlbigidmlzaXRmai5pbiIsInIiLHN0ZGluKTsKCWZyZW9wZW4oInZpc2l0Zmoub3V0IiwidyIsc3Rkb3V0KTsKfQppbnQgbix0LG14W109ezEsLTEsMCwwfSx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