#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define ld long double
#define iloop(m, h) for (ll i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define iloop_(m, h, g) for (auto i = m; i != h; i += g)
#define jloop_(m, h, g) for (auto j = m; j != h; j += g)
#define kloop_(m, h, g) for (auto k = m; k != h; k += g)
#define lloop_(m, h, g) for (auto l = m; l != h; l += g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
ll n, m;
pair<pll, pll> a[200005];
ll t[200005];
bool cmp(pair<pll, pll> t1, pair<pll, pll> t2) {
return t1.first.second < t2.first.second;
}
struct node {
ll s, e, m, v;
bool lcl = 0, rcl = 0;
node *l, *r;
node (ll S, ll E) {
s = S, e = E, m = (S+E)>>1;
v = 0;
}
void lcreate() {
if (s == e || lcl) return;
l = new node(s, m);
lcl = 1;
}
void rcreate() {
if (s == e || rcl) return;
r = new node(m+1, e);
rcl = 1;
}
void upd(ll X, ll V) {
if (s == e) {
v = V;
return;
}
if (X <= m) {lcreate(); l->upd(X, V);}
else {rcreate(); r->upd(X, V);}
v = 0;
if (lcl) v = max(v, l->v);
if (rcl) v = max(v, r->v);
}
ll query(ll S, ll E) {
if (S > E) return 0;
if (s == S && e == E) return v;
if (E <= m) {lcreate(); return l->query(S, E);}
if (S > m) {rcreate(); return r->query(S, E);}
lcreate(), rcreate();
return max(l->query(S, m), r->query(m+1, E));
}
} *root = new node(1, 1e9);
struct node2 {
ll s, e, m, v;
bool lcl = 0, rcl = 0;
node2 *l, *r;
node2 (ll S, ll E) {
s = S, e = E, m = (S+E)>>1;
v = 0;
}
void lcreate() {
if (s == e || lcl) return;
l = new node2(s, m);
lcl = 1;
}
void rcreate() {
if (s == e || rcl) return;
r = new node2(m+1, e);
rcl = 1;
}
void upd(ll X, ll V) {
if (s == e) {
v += V;
return;
}
if (X <= m) {lcreate(); l->upd(X, V);}
else {rcreate(); r->upd(X, V);}
v = 0;
if (lcl) v += l->v;
if (rcl) v += r->v;
}
ll query(ll S, ll E) {
if (s == S && e == E) return v;
if (E <= m) {lcreate(); return l->query(S, E);}
if (S > m) {rcreate(); return r->query(S, E);}
lcreate(), rcreate();
return l->query(S, m) + r->query(m+1, E);
}
} *root2 = new node2(1, 1e9);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
iloop(0, n) {
cin >> a[i].second.first >> a[i].second.second;
}
iloop(0, m) {
cin >> t[i];
root->upd(t[i], i+1);
}
iloop(0, n) {
a[i].first.first = root->query(min(a[i].second.first, a[i].second.second), max(a[i].second.first, a[i].second.second) - 1);
a[i].first.second = i;
}
sort(a, a+n, greater<pair<pll, pll>>());
ll cptr = m;
iloop(0, n) {
while (cptr > a[i].first.first) {
root2->upd(t[cptr-1], 1);
cptr--;
}
ll cm = root2->query(max(a[i].second.first, a[i].second.second), 1e9);
if (cptr) {
if (cm%2 == 0) a[i].first.first = max(a[i].second.first, a[i].second.second);
else a[i].first.first = min(a[i].second.first, a[i].second.second);
}
else {
if (cm%2 == 0) a[i].first.first = a[i].second.first;
else a[i].first.first = a[i].second.second;
}
}
ll ans = 0;
iloop(0, n) ans += a[i].first.first;
cout << ans;
}