#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;

#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);

#define lson (node<<1)
#define rson ((node<<1)|1)

const int mx = 2e5 + 9;

ll t[4 * mx];
vector <int> min_row[mx];

void turn_on(int node, int l, int r, int pos) {
    int mid = (l + r) / 2;
    if (l == r) {
        t[node] = 1;
        return;
    }

    if (pos <= mid) turn_on(lson, l, mid, pos);
    else turn_on(rson, mid + 1, r, pos);

    t[node] = t[lson] + t[rson];
}

ll query(int node, int l, int r, int L, int R) {
    int mid = (l + r) / 2;

    if (r < L or R < l) return 0;
    if (L <= l and r <= R) return t[node];

    ll q1 = query(lson, l, mid, L, R);
    ll q2 = query(rson, mid + 1, r, L, R);

    return q1 + q2;
}

int main() {
    FIO();

    int h, w, m;
    cin >> h >> w >> m;

    vector <int> row(h + 3, w + 1), col(w + 3, h + 1);

    while (m--) {
        int x, y;
        cin >> x >> y;

        row[x] = min(row[x], y);
        col[y] = min(col[y], x);
    }

    ll ans = 0;
    for (int i = 1; i <= w; i++) {
        if (i < row[1]) {
            ans += (col[i] - 1);
            min_row[col[i]].push_back(i);
        } else min_row[1].push_back(i);
    }

//    cout << ans << '\n';

    for (int i = 1; i < col[1]; i++) {
        for (int idx : min_row[i]) turn_on(1, 1, w, idx);
        if (row[i] == 1) continue;

        ll cnt = query(1, 1, w, 1, row[i] - 1);
        ans += cnt;

//        cout << i << " " << cnt << " " << row[i] << '\n';
    }

    cout << ans << '\n';
}

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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define F0R(i, a, b) for (int i=a; i<(b); i++)
#define F0Rd(i,a,b) for (int i = (b)-1; i >= a; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll M = 1e9 + 7;
const ll MM = 998244353;
const ll INF = 1e18;

void solve() {
	int N, K; cin >> N >> K;
	int cur = 0, yen = K;
	vector<pii> V(N);
	for(int i = 0; i < N; ++i) {
		cin >> V[i].F >> V[i].S;
	}
	sort(ALL(V));
	for(int i = 0; i < N; i++) {
		// D1(K);
		// D1(V[i].F);
		if(K >= V[i].F) K += V[i].S;
	}
	cout << K << '\n';
}

int32_t main() {
	_

	// tc(t)
	solve();
	// cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}