/*
This is code of SuperJ6 for Codeforces.
Don't copy my code during f*kin' contests.

2.71828182845904523536
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 52;
int n, k;
ll a[mxn];
ll f[mxn][2];
ll dp[mxn][mxn][mxn][4][4];

ll sol(int z, int l, int r, int x, int y){
	ll &dpc = dp[z][l][r][x][y];
	if(~dpc) return dpc;
	// if z == k, if l + 1 == r the setup is possible, otherwise still then we need to test other values to make sure state is possible.
	// if z != k, we can try assuming all bits within l and r can be set to anything then worry about next highest bit
	if(z == k) dpc = (l + 1 != r) * 0x3f3f3f3f3f3f3f3f;
	else dpc = sol(z + 1, l, r, x & 2, y & 2) + (l && r <= n && // x & 2, y & 2 make sure rest of bits will now be equal to bound based on key bit
		((((f[l][x >> 1] ^ f[r][y >> 1]) >> z) ^ x ^ y) & 1)) * a[z]; // tests whether edge bits are equal, and if not there must be transition somewhere in range where one consecutive element has 0 and the other has 1
		
	for(int i = l + 1; i < r; i++) if((f[i][0] ^ f[i][1]) >> (z + 1)) // is key bit higher
	for(int j = 0; j < 2; j++) if(((f[i][j] >> z) & 1) == j){ // can you set this bit so it becomes within bound
		// j is the value you are setting the key bit too, ie do u have to worry about lower or upper bound
		// | 1 shows that this value will be opposite the bound bit so it will fit in bounds
		dpc = min(dpc, sol(z, l, i, x, j << 1 | 1) + sol(z, i, r, j << 1 | 1, y));
	}
	
	return dpc;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++){
		cin >> f[i][0] >> f[i][1];
		f[i][0]--, f[i][1]++;
	}
	
	for(int i = 0; i < k; i++) cin >> a[i];
	
	memset(dp, -1, sizeof(dp));
	
	cout << sol(0, 0, n + 1, 0, 0) << endl;

	return 0;
}