//CF1456E
#include <bits/stdc++.h>
#define MP std::make_pair
#define PB push_back
#define FI first
#define SE second
typedef long long ll;
const ll max_N = 55;
const ll INF = 1e18;
ll n, K, L[max_N], R[max_N], C[max_N], dp[max_N][max_N][max_N][2][2][2][2], BL[1 << 17], BM[1 << 17], BR[1 << 17];
bool flag[max_N][max_N][2];
ll read() {
	char c = getchar(); ll ans = 0;
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(ll x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll x, ll y) {return x > y ? x : y;}
ll calcl(ll x, ll w, bool flag = false) {
	if (flag) return x & ~((1ll << w - 1) - 1);
	return (x | (1ll << w - 1)) & ~((1ll << w - 1) - 1);
}
ll calcr(ll x, ll w, bool flag = false) {
	if (flag) return x & ~((1ll << w - 1) - 1);
	return x & ~((1ll << w) - 1);
}
void prepare() {
	static ll Map[1 << 17];
	for (ll i = 0; i < 17; i++) Map[1 << i] = C[i];
	for (ll i = 1; i < (1 << 17); i++)
		BL[i] = BL[i & (i - 1)] + Map[i & -i];
	for (ll i = 0; i < 17; i++) Map[1 << i] = C[i + 17];
	for (ll i = 1; i < (1 << 17); i++)
		BM[i] = BM[i & (i - 1)] + Map[i & -i];
	for (ll i = 0; i < 17; i++) Map[1 << i] = C[i + 34];
	for (ll i = 1; i < (1 << 17); i++)
		BR[i] = BR[i & (i - 1)] + Map[i & -i];
}
ll calc(ll x, ll w1, ll w2) {
	x &= ~((1ll << w1) - 1), x &= ((1ll << w2 + 1) - 1);
	return BL[x & 131071] + BM[x >> 17 & 131071] + BR[x >> 34];
}
int main() {
	n = read(), K = read() + 1;
	for (ll i = 1; i <= n; i++) L[i] = read() * 2, R[i] = read() * 2 + 1;
	for (ll i = 1; i < K; i++) C[i] = read();
	prepare();
	for (ll i = 1; i <= n; i++) {
		for (ll j = 0; j < K; j++)
			if (!(L[i] >> j & 1) && (L[i] | ((1ll << j + 1) - 1)) <= R[i]) flag[i][j + 1][0] = true;
		for (ll j = 0; j < K; j++) {
			if ((R[i] >> j & 1) && (R[i] & ~((1ll << j + 1) - 1)) >= L[i]) flag[i][j + 1][1] = true;
		}
	}
	for (ll i = 0; i <= n; i++)
		for (ll j = 0; j <= n; j++)
			for (ll k = 0; k <= K; k++)
				for (ll x = 0; x < 2; x++)
					for (ll y = 0; y < 2; y++)
						for (ll sx = 0; sx < 2; sx++)
							for (ll sy = 0; sy < 2; sy++) dp[i][j][k][x][y][sx][sy] = INF;
	for (ll i = 1; i <= n + 1; i++)
		for (ll j = 0; j <= K; j++)
			for (ll x = 0; x < 2; x++)
				for (ll y = 0; y < 2; y++)
					for (ll sx = 0; sx < 2; sx++)
						for (ll sy = 0; sy < 2; sy++) dp[i][i - 1][j][x][y][sx][sy] = 0;
	for (ll _ = 1; _ <= n; _++)
		for (ll i = 1, j = _; j <= n; i++, j++)
			for (ll l = K; l; l--)
				for (ll x = 0; x < 2; x++)
					for (ll y = 0; y < 2; y++)
						for (ll sx = 0; sx < 2; sx++)
							for (ll sy = 0; sy < 2; sy++) {
								ll _i = (x ? calcr(R[i - 1], l, !sx) : calcl(L[i - 1], l, !sx));
								ll _j = (y ? calcr(R[j + 1], l, !sy) : calcl(L[j + 1], l, !sy));
								if (l < K) dp[i][j][l][x][y][sx][sy] = min(dp[i][j][l][x][y][sx][sy],
								dp[i][j][l + 1][x][y][0][0] + (i > 1 && j < n ? calc(_i ^ _j, l - 1, l - 1) : 0));	
								for (ll mid = i; mid <= j; mid++)
									for (ll nxtl = l; nxtl <= l; nxtl++)
										for (ll z = 0; z < 2; z++) {
											if (!flag[mid][nxtl][z]) continue;
											ll _mid = (z ? calcr(R[mid], nxtl) : calcl(L[mid], nxtl));
											ll dl = dp[i][mid - 1][nxtl][x][z][sx][1];
											if (i > 1 && mid == i) dl += calc(_i ^ _mid, nxtl - 1, K - 1);
											ll dr = dp[mid + 1][j][nxtl][z][y][1][sy];
											if (j < n && mid == j) dr += calc(_mid ^ _j, nxtl - 1, K - 1);
											dp[i][j][l][x][y][sx][sy] = min(dp[i][j][l][x][y][sx][sy], dl + dr);
										}
							}
	return Write(dp[1][n][1][0][0][0][0]), 0;
}
