#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
// #pragma GCC optimize("unroll-loops")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 998244353;

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n), b(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<ll> p(n);
    for (ll i = 0; i < n; i++) {
        cin >> p[i];
    }
    ll ans = 0;
    ll s = 0;
    for (ll i = 0; i < n; i++) {
        s += a[i];
        ans = max(ans, s);
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
