using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 57
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
int n,k;
ll lim[N][2];
int lg(ll x){
	ll c=0;
	for (;x;x>>=1)
		++c;
	return c;
}
int kb[N];
ll c[N];
ll f[N][N][N][4][4];//(0/1,0/1) keybit , if equal to i 
void tran(ll &x,ll y){x>y?x=y:0;}
bool judge(int l,int r,int i){
	for (int md=l+1;md<=r-1;++md)
		if (i>=kb[md]-1)
			return 0;
	return 1;
}
int main(){
//	printf("%lld\n",sizeof(f));
//	return 0;
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;++i){
		scanf("%lld%lld",&lim[i][0],&lim[i][1]);
		lim[i][0]+=1ll<<k,lim[i][1]+=1ll<<k;
		lim[i][0]--,lim[i][1]++;
		kb[i]=lg(lim[i][0]^lim[i][1])-1;
	}
	lim[0][0]=lim[1][0],lim[0][1]=lim[1][1],kb[0]=kb[1];
	lim[n+1][0]=lim[n][0],lim[n+1][1]=lim[n][1],kb[n+1]=kb[n];
	for (int i=0;i<k;++i)
		scanf("%lld",&c[i]);
	k+=2;
	memset(f,63,sizeof f);
	for (int l=0,r;l<=n+1;++l){
		r=l+1;
		for (int sl=0;sl<2;++sl)
			for (int sr=0;sr<2;++sr)
				f[k][l][r][sl][sr]=0;
	}
	for (int i=k-1;i>=0;--i){
		for (int l=n+1;l>=0;--l)
			for (int r=l+1;r<=n+1;++r){
				for (int sl=0;sl<4;++sl)
					for (int sr=0;sr<4;++sr){
						if (sl>>1 && !(i<kb[l] && (lim[l][sl&1]>>i&1)==(sl&1)))
							continue;
						if (sr>>1 && !(i<kb[r] && (lim[r][sr&1]>>i&1)==(sr&1)))
							continue;
						if (judge(l,r,i))
							tran(f[i][l][r][sl][sr],f[i+1][l][r][sl&1][sr&1]+(1<=l && r<=n?((lim[l][sl&1]>>i&1^sl>>1)^(lim[r][sr&1]>>i&1^sr>>1))*c[i]:0));
						for (int md=l+1;md<=r-1;++md){
							tran(f[i][l][r][sl][sr],f[i][l][md][sl][2]+f[i][md][r][2][sr]);
							tran(f[i][l][r][sl][sr],f[i][l][md][sl][3]+f[i][md][r][3][sr]);
						}
					}
			}
	}
	ll ans=INF;
	for (int sl=0;sl<4;++sl)
		for (int sr=0;sr<4;++sr)
			ans=min(ans,f[0][0][n+1][sl][sr]);
	printf("%lld\n",ans);
	return 0;
}
