#include <bits/stdc++.h>
using namespace std;


using ll = long long;

class Edge{
public:
    int from, to;
    long long value;
    Edge(int a, int b, long long c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};

std::vector<long long> dijkstra(int s, int N, std::vector<Edge> E){
    std::vector<long long> ans(N, 1e18);
    std::vector<std::vector<Edge>> Edges(N);
    for(auto e : E){
        Edges.at(e.from).push_back(e);
    }
    std::priority_queue<std::pair<long long, int>, std::vector<std::pair<long long, int>>, std::greater<std::pair<long long, int>>> que;
    ans.at(s)= 0;
    que.push(std::make_pair(0, s));
    while(!que.empty()){
        std::pair<long long, int> p = que.top();
        que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(std::make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}

void solve(long long a, long long b, long long x, long long y){
    vector<Edge> Edges;
    for(int i = 0;i < 100;i++){
        Edges.push_back(Edge(i, i + 100, x));
    }
    for(int i = 0;i < 99;i++){
        Edges.push_back(Edge(i + 1, i + 100, x));
    }
    for(int i = 0;i < 99;i++){
        Edges.push_back(Edge(i, i + 1, y));
        Edges.push_back(Edge(i + 100, i + 100 + 1, y));
    }
    int q = Edges.size();
    for(int i = 0;i < q;i++){
        Edges.push_back(Edge(Edges[i].to, Edges[i].from, Edges[i].value));
    }
    vector<ll> dist = dijkstra(a - 1, 2 * 100, Edges);
    cout<<dist[(b - 1) + 100]<<endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(a, b, x, y);
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
//const int mod = 998244353;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

LL N,K;

bool check(LL mid, const VVL& A){
    dump(mid)
    LL half = (K*K+1) / 2;
    VVL acc(N,VL(N));
    REP(i,N) REP(j,N){
        if(i == 0 && j == 0){
            if(A[0][0] <= mid) acc[i][j] = 1;
            else acc[i][j] = 0;
        }else if(i == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i][j-1] + 1;
            }else{
                acc[i][j] = acc[i][j-1];
            }
        }else if(j == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + 1;
            }else{
                acc[i][j] = acc[i-1][j];
            }
 
        }else{
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1] + 1;
            }else{
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1];
            }
 
        }
    }

    //REP(i,N){
    //    REP(j,N){
    //        cerr << acc[i][j] << " ";
    //    }
    //    cerr << endl;
    //}

    REP(i,N) REP(j,N){
        if(i-K < -1 or j-K < -1) continue;
        LL tx,ty,tz;
        if(i-K == -1){
            tx = 0;
        }else{
            tx = acc[i-K][j];
        }

        if(j-K == -1){
            ty = 0;
        }else{
            ty = acc[i][j-K];
        }

        if(i-K == -1 or j-K == -1){
            tz = 0;
        }else{
            tz = acc[i-K][j-K];
        }


        //LL cnt = acc[i][j] - acc[i-K][j] - acc[i][j-K] + acc[i-K][j-K];
        LL cnt = acc[i][j] - tx - ty + tz;
        

        dump(cnt)
            dump(half)
        if(cnt >= half) {
            return true;
        }

    }
    return false;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    //LL N,K;
    cin >> N >> K;
    vector<VL> A(N,VL(N));


    REP(i,N) REP(j,N){
        cin >> A[i][j];
    }

    LL ok = INF;
    //LL ng = INF;
    LL ng = -1;

    while(abs(ok-ng) > 1){
        LL mid = (ok + ng) / 2;

        if(check(mid,A)){
            dump("ok")
            ok = mid;
        }else{
            dump("ng")
            ng = mid;
        }

    }
    cout << ok << endl;

}