#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int a[4];
    int ans = INF;
    rep(i, 4) {
        cin >> a[i];
        ans = min(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
 
 
//const int MOD=998244353;

vector<int> dij(vector<vector<pair<int,int>>> graph, int source){
    int n=graph.size();
    vector<int> dists(n,MOD);
    vector<bool> mark(n,false);
    dists[source]=0;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({dists[source],source});
    while(!pq.empty()){
        auto cur=pq.top();
        pq.pop();
        int v=cur.second;
        //cout<<v<<" "<<dists[v]<<" "<<cur.first<<endl;
        if(mark[v]) continue;
        mark[v]=true;
        for(auto& p:graph[v]){
            if(dists[p.first]>dists[v]+p.second){
                dists[p.first]=dists[v]+p.second;
                pq.push({dists[p.first],p.first});
            }
        }
    }
    return dists;
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b,x,y;
    cin>>a>>b>>x>>y;
    
    vector<vector<pair<int,int>>> gr(202);
    
    for(int i=1; i<=100; i++){
        gr[i].push_back({100+i,x});
        gr[100+i].push_back({i,x});
    }
    
    for(int i=2; i<=100; i++){
        gr[i].push_back({100+i-1,x});
        gr[100+i-1].push_back({i,x});
        
    }
    
    for(int i=1; i<=99; i++){
        gr[i].push_back({i+1,y});
        gr[i+1].push_back({i,y});
        gr[100+i].push_back({100+i+1,y});
        gr[100+i+1].push_back({100+i,y});
    }
    
    auto v=dij(gr,a);
    cout<<v[100+b];
    
    
    return 0;
}