//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

//#define pb push_back
//#define mp make_pair
#define fi first
#define se second

typedef long long ll;

//#define rep(_i,iv,n) for(int _i=(int)(iv);_i<(int)(n);++_i)
#define rep0(_i,n) for(int _i=0;_i<(int)(n);++_i)
//#define REP(_i,iv,_l,n) for(int _i=(int)(iv),_l=(int)(n);_i<_l;++_i)
#define REP0(_i,_l,n) for(int _i=0,_l=(int)(n);_i<_l;++_i)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;

typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
typedef vector<vll > vvll;

#define INF 1<<30

td pair<int, int > pii;
td priority_queue<pii,vector<pii>,greater<pii> > pq;

#define mod7 1000000007

void init(int S, int *tree, int i) {
    if (i >= S) {
        return;
    }
    init(S, tree, i * 2);
    init(S, tree, i * 2 + 1);
    tree[i] = tree[i * 2] ^ tree[i * 2 + 1];
}

void update(int *tree, int i) {
    if (i == 1) {
        return;
    }
    int pi = i / 2;
    tree[pi] = tree[pi * 2] ^ tree[pi * 2 + 1];
    update(tree, pi);
}

int show(int *tree, int l) {
    int ans = tree[l];
    for (int i = l; i != 1; i /= 2) {
        if (i % 2) {
            ans ^= tree[i - 1];
        }
    }
    return ans;
}

int getS(int N) {
    for (int i = 1; ; ++i) {
        if (N <= (1 << i)) {
            return 1 << i;
        }
    }
}


int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    int A[N], B[N];
    rep0(i, N) {
        cin>>A[i]>>B[i];
    }
    
    int tMin = INT32_MAX;
    rep0(i, N) {
        rep0(j, N) {
            int t;
            if (i == j) {
                t = A[i]+B[j];
            } else {
                t = max(A[i], B[j]);
            }
            if (t <tMin) {
                tMin = t;
            }
        }
    }
    cout << tMin <<endl;
    
    
    return 0;
}

/*	_____________________
	|Author : canhnam357|
	|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
int CASE = 1;
const int mxn = 4e3 + 1;
const ll INF = 1e18;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 1e5;
bool prime(ll n)
{
	if (n <= 1)
		return false;
	eFOR(i, 2, sqrt(n))
		if (!(n % i))
			return false;
	return true;
}
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
void solve()
{
	int a, b, x, y;
	cin >> a >> b >> x >> y;	
	if (b >= a)
	{
		cout << x + min(2 * x, y) * (b - a);
	}
	else
	{
		int k = a - b;
		cout << min(x + (k - 1) * y, (2 * k - 1) * x);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}