import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

const long INF = long.max / 2;

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto S = new int[N],
         T = new int[N],
         P = new long[M + 1];
    foreach (i; 0 .. N) scanf("%d %d\n", &S[i], &T[i]);
    foreach (i; 1 .. M + 1) scanf("%d\n", &P[i]);
    P ~= INF;
    
    P = P.sort.uniq.array;

    auto X = new long[][](2, M + 2);
    foreach (i; 0 .. M + 1) {
        X[0][i + 1] = X[0][i];
        X[1][i + 1] = X[1][i];
        X[i & 1][i + 1] += P[i + 1] - P[i];
    }

    const DEBUG = false;

    long Ans = 0;
    foreach (i; 0 .. N) {
        int s = S[i], t = T[i];
        bool swapped = s > t;
        if (s > t) swap(s, t);
        auto us = P.assumeSorted.lowerBound(s).length;
        auto lt = P.assumeSorted.lowerBound(t).length;
        if (us == lt) { Ans += t - s; continue; }
        lt--;
        auto flag = us % 2 == 0;
        long L = 0;
        static if (DEBUG) writeln("\t", [s, t, us, lt]);
        L += X[flag][lt] - X[flag][us];
        static if (DEBUG) writeln("ADD ", X[flag][lt] - X[flag][us]);
        L += P[us] - s;
        static if (DEBUG) writeln("ADD ", P[us] - s);
        if ((lt - us) % 2 == 1) {
            L += t - P[lt];
            static if (DEBUG) writeln("ADD ", t - P[lt]);
        }
        Ans += (!swapped || (lt - us) % 2 == 1) ? L : (t - s) - L;
    }
    writeln(Ans);
}