#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
 
using namespace std;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
 
typedef long long ll;
typedef long double ld;
 
void run_case();

int32_t main () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    #endif
    int t = 1;
    // cin >> t; 
    while (t--) { 
        run_case();
    }
    return 0;
}
const int N = 2e5 + 5;
int x[N], id[N];
int n;
set<int> s;
map<int, int> comp;
int pt[N][2];
int dp[N][2];
void run_case() {
    cin >> n;
    pt[0][0] = pt[0][1] = 0;
    for (int i = 1; i <= n; ++i) {
        pt[i][0] = 1e9 + 5;
        pt[i][1] = -1e9 - 5;
        cin >> x[i] >> id[i];
        s.insert(id[i]);
    }
    int cur = 0;
    for (auto i : s) comp[i] = ++cur;
    for (int i = 1; i <= n; ++i) id[i] = comp[id[i]], pt[id[i]][1] = max(pt[id[i]][1], x[i]), pt[id[i]][0] = min(pt[id[i]][0], x[i]);
    pt[(int) comp.size() + 1][0] = 0;
    pt[(int) comp.size() + 1][1] = 0;
    dp[0][0] = dp[0][1] = 0;
    for (int i = 1; i < N; ++i) dp[i][0] = dp[i][1] = 1e18;
    for (int i = 1; i <= (int) comp.size() + 1; ++i) {
        for (int prv = 0; prv < 2; ++prv) {
            for (int cur = 0; cur < 2; ++cur) {
                dp[i][cur] = min(dp[i][cur], dp[i - 1][prv] + llabs(pt[i - 1][prv] - pt[i][cur ^ 1]) + llabs(pt[i][cur ^ 1] - pt[i][cur]));
            }
        }
    }
    cout << dp[(int) comp.size() + 1][0];
}  
#include <bits/stdc++.h>
using namespace std ;
using ll = long long;
#define ffor(n) for(ll i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()



using ld = long double;

using pi = pair<int,int>;
using pl = pair<ll,ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<ld>;


using vpi = vector<pair<int,int>>;

void solve(){
	ll n,q;
    cin>>n>>q;
	vl v(n);
	ffor(n)
	{
		ll a;cin>>a;
		v[i] = a;
	}
	sort(all(v));
	while(q--)
	{
		ll b;cin>>b;
		ll k=b;
		ll c = -1;
		ll it = -2;
		ll i = 0;
		while(!(c == it))
		{
		c = it;
		it = upper_bound(all(v),b)-v.begin();
		if(i)b += (it-c);
		else b += it;
		i++;
		}
		cout<<k+it<<"\n";


	}
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
	//cin>>t;
	while(t--)
	{
           solve();
	}
	return 0;
}