#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int> > st(n);
  for(int i = 0; i < n; ++i)
    cin >> st[i].first >> st[i].second;
  vector<int> p(m);
  for(int i = 0; i < m; ++i){
    cin >> p[i];
  }
  vector<ll> sum1(1),sum2(1);
  p.push_back(-100);
  p.push_back(2e9);
  sort(p.begin(),p.end());

  for(int i = 1; i < p.size(); ++i){
    if(i&1){
      sum1.push_back(sum1.back() + p[i]-p[i-1]);
      sum2.push_back(sum2.back());
    }else{
      sum2.push_back(sum2.back() + p[i]-p[i-1]);
      sum1.push_back(sum1.back());
    }
  }
  
  
  long long ans = 0;
  for(int i = 0; i < n; ++i){
    if(st[i].first > st[i].second){
      // int pidx = lower_bound(p.begin(), p.end(), st[i].first) - p.begin();
      // --pidx;
      // while(pidx >= 0 && p[pidx+1] > st[i].second){
      //   ans += min(st[i].first, p[pidx+1]) - max(st[i].second, p[pidx]);
      //   pidx -= 2;
      // }
      {
        int sidx = lower_bound(p.begin(), p.end(), st[i].second) - p.begin();
        int eidx = lower_bound(p.begin(), p.end(), st[i].first) - p.begin();
        if(sidx == eidx){
          ans += st[i].first - st[i].second;
          continue;
        }
        vector<long long>* use = eidx&1?&sum1:&sum2;
        ans += st[i].first - p[eidx-1];
        if((sidx&1) == (eidx&1)){
          ans += p[sidx] - st[i].second;
          //++sidx;
        }
        ans += max(0LL, (*use)[eidx-1] - (*use)[sidx]);
      }
    }else{
      // int pidx = lower_bound(p.begin(), p.end(), st[i].first) - p.begin();
      // while(pidx < p.size() && p[pidx-1] < st[i].second){
      //   ans += min(st[i].second, p[pidx]) - max(st[i].first, p[pidx-1]);
      //   pidx += 2;
      // }
      {
        int sidx = lower_bound(p.begin(), p.end(), st[i].first) - p.begin();
        int eidx = lower_bound(p.begin(), p.end(), st[i].second) - p.begin();
        if(sidx == eidx){
          ans += st[i].second - st[i].first;
          continue;
        }
        vector<long long>* use = sidx&1?&sum1:&sum2;
        ans += p[sidx] - st[i].first;
        if((sidx&1) == (eidx&1)){
          ans += st[i].second - p[eidx-1];
          --eidx;
        }
        ans += max(0LL, (*use)[eidx] - (*use)[sidx]);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4760