    #include<bits/stdc++.h>
    using namespace std;

    #define ll long long int
    #define ull unsigned long long
    #define pll pair<ll,ll>
    #define MS(x, y) memset(x, y, sizeof(x))
    #define all(x) x.begin(),x.end()
    #define ff first
    #define ss second
    #define INFL LLONG_MAX
    #define pb push_back
    #define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    const ll N = 2e5 + 5;
    const ll M = 1e5 + 5;
    const ll mod = 1e9 + 7;
    const ll m1 = 1e9 + 7;
    const ll m2 = 1e9 + 9;
    const ll p1 = 402653189;
    const ll p2 = 1610612741;
    const int LN = 32;

    ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
    ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
    ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

    ll dx[4]={-1,  1,  0,  0};
    ll dy[4]={ 0,  0,  1, -1};

    ll pw[LN],fact[N],invfact[N];

    void pre()
    {
        fact[0]=1;
        for(int i=0;i<LN;i++)pw[i]=power(2,i);
        for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
        for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
    }

    pll pos[N];
    vector <ll> col;
    set <ll> s;

    int main()
    {
        FIO;
        //pre();

        ll i,j;

        ll n,m,k,q;
        cin>>n>>m>>k>>q;

        pos[0] = {1,1};
        s.insert(1);

        for(i=1;i<=k;i++)
        {
            cin>>pos[i].ff>>pos[i].ss;
            s.insert(pos[i].ff);
        }

        sort(pos,pos+k+1);

        for(i=1;i<=q;i++)
        {
            ll val;
            cin>>val;
            col.pb(val);
        }

        sort(all(col));

        vector <pll> ans;
        ans.pb({1,-1});
        ll idx = 0;

        ll fans = 0;

        for(auto it:s)
        {
            ll tmpidx = idx;
            while(tmpidx<=k && pos[tmpidx].ff == it)
                tmpidx++;
            tmpidx--;
            //cout<<"idx -> "<<idx<<"  "<<tmpidx<<"\n";

            if(tmpidx == k)
            {
                if(idx == 0)
                    fans = 1;
                else
                    fans = pos[idx].ff - pos[idx-1].ff;
                break;
            }

            vector <pll> tmpans = ans;
            ans.clear();

            /*for(auto it:tmpans)
                cout<<it.ff<<"  "<<it.ss<<"\n";
            cout<<"\n";*/

            ll y1 = pos[idx].ss;
            ll y2 = pos[tmpidx].ss;

            ll id = upper_bound(all(col),y1) - col.begin();

            if(id != col.size())
            {
                ll tans = INFL;

                for(auto x: tmpans)
                {
                    if(x.ff<=y1)
                    {
                        if(col[id]<=y2)
                        {
                            tans = min(tans , x.ss + y2 - x.ff + y2 - col[id]);
                        }
                        else
                        {
                            tans = min(tans , x.ss + col[id] - x.ff);
                        }
                    }
                    else if(x.ff>=y1 && x.ff<=y2)
                    {
                        if(col[id]<=y2)
                        {
                            tans = min(tans , x.ss + min( y2 - x.ff + y2 - y1 + col[id] - y1 , x.ff - y1 + y2 - y1 + y2 - col[id]));
                        }
                        else
                        {
                            tans = min(tans , x.ss + x.ff - y1 + col[id] - y1);
                        }
                    }
                    else
                    {
                        tans = min(tans , x.ss + x.ff - y1 + col[id] - y1);
                    }
                }
                if(idx == 0)
                    ans.pb({col[id],tans+1});
                else
                    ans.pb({col[id],tans + pos[idx].ff - pos[idx-1].ff});
            }

            id = upper_bound(all(col),y2) - col.begin();

            if(id != col.size())
            {
                ll tans = INFL;

                for(auto x:tmpans)
                {
                    if(x.ff<=y1)
                    {
                        tans = min(tans , x.ss - x.ff + col[id]);
                    }
                    else if(x.ff>=y1 && x.ff<=y2)
                    {
                        tans = min(tans , x.ss + x.ff - y1 + col[id] - y1);
                    }
                    else
                    {
                        tans = min(tans , x.ss + x.ff - y1 + col[id] - y1);
                    }
                }
                if(idx == 0)
                    ans.pb({col[id],tans+1});
                else
                    ans.pb({col[id],tans + pos[idx].ff - pos[idx-1].ff});
            }

            idx = tmpidx + 1;
        }

        ll fin_ans = INFL;

        for(auto it:ans)
        {
            ll y1 = pos[idx].ss , y2 = pos[k].ss;

            if(it.ff <= y1)
            {
                fin_ans = min(fin_ans , fans + it.ss + y2 - it.ff);
            }
            else if(it.ff >= y1 && it.ff <= y2)
            {
                fin_ans = min(fin_ans , fans + it.ss + min(it.ff - y1 + y2 - y1 , y2 - it.ff + y2 - y1));
            }
            else
            {
                fin_ans = min(fin_ans , fans + it.ss + it.ff - y1);
            }
        }

        cout<<fin_ans;

        return 0;
    }


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}
	for(int i=0;i<r;i++){
		cout << tr[i][0] << ' ' << tr[i][1] << endl;
	}
	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2] = {{tr[min_h][0], tr[min_h][0]}, {tr[min_h][1], tr[min_h][1]}}; // two cases, (x_pos, step)

	for(int r_i=min_h+1;r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		int new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				int to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				int to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2] = {{tr[min_h][0], tr[min_h][0]}, {tr[min_h][1], tr[min_h][1]}}; // two cases, (x_pos, step)

	for(int r_i=min_h+1;r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		int new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				int to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				int to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2] = {{tr[min_h][1], tr[min_h][1]}, {tr[min_h][1], tr[min_h][1]}}; // two cases, (x_pos, step)

	for(int r_i=min_h+1;r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		int new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				int to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				int to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define int ll
#define fi first
#define se second
#define p 1000000007

typedef long long ll;

int Q[200000];
vvi tea(200000);
int prec[200000][2];

int32_t main(){
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	int Level = -1;
	int Small = 1 << 30;
	for(int i=0;i<k;i++){
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		tea[v1].pb(v2);
		Level = max(Level, v1);
		Small = min(Small, v1);
	}
	for(int i=0;i<q;i++){
		int v;
		cin >> v;
		v--;
		Q[i] = v;
	}
	sort(Q, Q+q);
	for(int i=0;i<m;i++){
		if(binary_search(Q, Q+q, i)){
			prec[i][0] = prec[i][1] = i;
		}else{
			if(upper_bound(Q, Q+q, i) == Q+q){
				prec[i][0] = prec[i][1] = *(upper_bound(Q, Q+q, i) - 1);
			}else if(upper_bound(Q, Q+q, i) == Q){
				prec[i][0] = prec[i][1] = *upper_bound(Q, Q+q, i);
			}else{
				prec[i][0] = *(upper_bound(Q, Q+q, i) - 1);
				prec[i][1] = *upper_bound(Q, Q+q, i);
			}
		}
	}
	vector<pair<int, int>> curState; // move, x_cord
	vector<pair<int, int>> nextState;
	ll ans = Level;
	for(int i=0;i<n;i++){
		if(tea[i].size() == 0){
			continue;
		}
		curState.clear();
		if(i == Small){
			curState.pb(pair<int, int>{0, 0});
		}
		for(auto j:nextState){
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][0]), prec[j.se][0]});
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][1]), prec[j.se][1]});
		}
		nextState.clear();
		sort(tea[i].begin(), tea[i].end());
		int _min = tea[i].front();
		int _max = tea[i].back();
		ll min_step = (1LL << 62);
		ll x_cord = -1;
		for(auto j:curState){ // end at _max
			int steps = j.fi + abs(j.se - _min) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _max;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
		min_step = (1LL << 62);
		x_cord = -1;
		for(auto j:curState){ // end at _min
			int steps = j.fi + abs(j.se - _max) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _min;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
	}
	ll ___min = (1LL << 62);
	for(auto i:nextState){
		___min = min(___min, (ll)i.fi);
	}
	ans += ___min;
	cout << ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2] = {{tr[min_h][1], tr[min_h][1]}, {tr[min_h][1], tr[min_h][1]}}; // two cases, (x_pos, step)

	for(int r_i=min_h+1;r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		ll new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				ll to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				ll to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	if(min_h == 0){
		ll pos[2][2] = {{tr[0][1], tr[0][1]}, {tr[0][1], tr[0][1]}}; // two cases, (x_pos, step)
	}else{
		ll pos[2][2] = {{safe[0][1], safe[0][1]}, {safe[0][1], safe[0][1]}}; // two cases, (x_pos, step)
	}

	for(int r_i=max(1, min_h);r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		ll new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				ll to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				ll to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define int ll
#define fi first
#define se second
#define p 1000000007

typedef long long ll;

int Q[200000];
vvi tea(200000);
int prec[200000][2];

int32_t main(){
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	int Level = -1;
	for(int i=0;i<k;i++){
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		tea[v1].pb(v2);
		Level = v1;
	}
	for(int i=0;i<q;i++){
		int v;
		cin >> v;
		v--;
		Q[i] = v;
	}
	sort(Q, Q+q);
	for(int i=0;i<m;i++){
		if(binary_search(Q, Q+q, i)){
			prec[i][0] = prec[i][1] = i;
		}else{
			if(upper_bound(Q, Q+q, i) == Q+q){
				prec[i][0] = prec[i][1] = *(upper_bound(Q, Q+q, i) - 1);
			}else if(upper_bound(Q, Q+q, i) == Q){
				prec[i][0] = prec[i][1] = *upper_bound(Q, Q+q, i);
			}else{
				prec[i][0] = *(upper_bound(Q, Q+q, i) - 1);
				prec[i][1] = *upper_bound(Q, Q+q, i);
			}
		}
	}
	vector<pair<int, int>> curState; // move, x_cord
	vector<pair<int, int>> nextState;
	ll ans = Level;
	for(int i=0;i<n;i++){
		if(tea[i].size() == 0){
			continue;
		}
		curState.clear();
		if(i == 0){
			curState.pb(pair<int, int>{0, 0});
		}
		for(auto j:nextState){
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][0]), prec[j.se][0]});
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][1]), prec[j.se][1]});
		}
		nextState.clear();
		sort(tea[i].begin(), tea[i].end());
		int _min = tea[i].front();
		int _max = tea[i].back();
		ll min_step = (1LL << 62);
		ll x_cord = -1;
		for(auto j:curState){ // end at _max
			int steps = j.fi + abs(j.se - _min) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _max;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
		min_step = (1LL << 62);
		x_cord = -1;
		for(auto j:curState){ // end at _min
			int steps = j.fi + abs(j.se - _max) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _min;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
	}
	ll ___min = (1LL << 62);
	for(auto i:nextState){
		___min = min(___min, (ll)i.fi);
	}
	ans += ___min;
	cout << ans;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define int ll
#define fi first
#define se second
#define p 1000000007

typedef long long ll;

int Q[200000];
vvi tea(200000);
int prec[200000][2];

int32_t main(){
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	int Level = -1;
	for(int i=0;i<k;i++){
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		tea[v1].pb(v2);
		Level = max(Level, v1);
	}
	for(int i=0;i<q;i++){
		int v;
		cin >> v;
		v--;
		Q[i] = v;
	}
	sort(Q, Q+q);
	for(int i=0;i<m;i++){
		if(binary_search(Q, Q+q, i)){
			prec[i][0] = prec[i][1] = i;
		}else{
			if(upper_bound(Q, Q+q, i) == Q+q){
				prec[i][0] = prec[i][1] = *(upper_bound(Q, Q+q, i) - 1);
			}else if(upper_bound(Q, Q+q, i) == Q){
				prec[i][0] = prec[i][1] = *upper_bound(Q, Q+q, i);
			}else{
				prec[i][0] = *(upper_bound(Q, Q+q, i) - 1);
				prec[i][1] = *upper_bound(Q, Q+q, i);
			}
		}
	}
	vector<pair<int, int>> curState; // move, x_cord
	vector<pair<int, int>> nextState;
	ll ans = Level;
	for(int i=0;i<n;i++){
		if(tea[i].size() == 0){
			continue;
		}
		curState.clear();
		if(i == 0){
			curState.pb(pair<int, int>{0, 0});
		}
		for(auto j:nextState){
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][0]), prec[j.se][0]});
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][1]), prec[j.se][1]});
		}
		nextState.clear();
		sort(tea[i].begin(), tea[i].end());
		int _min = tea[i].front();
		int _max = tea[i].back();
		ll min_step = (1LL << 62);
		ll x_cord = -1;
		for(auto j:curState){ // end at _max
			int steps = j.fi + abs(j.se - _min) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _max;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
		min_step = (1LL << 62);
		x_cord = -1;
		for(auto j:curState){ // end at _min
			int steps = j.fi + abs(j.se - _max) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _min;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
	}
	ll ___min = (1LL << 62);
	for(auto i:nextState){
		___min = min(___min, (ll)i.fi);
	}
	ans += ___min;
	cout << ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2] = {{tr[min_h][1], tr[min_h][1]}, {tr[min_h][1], tr[min_h][1]}}; // two cases, (x_pos, step)

	for(int r_i=min_h+1;r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		int new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				ll to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				ll to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define int ll
#define fi first
#define se second
#define p 1000000007

typedef long long ll;

int Q[200000];
int prec[200000][2];

int32_t main(){
	int n, m, k, q;
	cin >> n >> m >> k >> q;
	int Level = -1;
	for(int i=0;i<k;i++){
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		tea[v1].pb(v2);
		Level = max(v1, Level);
	}
	for(int i=0;i<q;i++){
		int v;
		cin >> v;
		v--;
		Q[i] = v;
	}
	sort(Q, Q+q);
	for(int i=0;i<m;i++){
		if(binary_search(Q, Q+q, i)){
			prec[i][0] = prec[i][1] = i;
		}else{
			if(upper_bound(Q, Q+q, i) == Q+q){
				prec[i][0] = prec[i][1] = *(upper_bound(Q, Q+q, i) - 1);
			}else if(upper_bound(Q, Q+q, i) == Q){
				prec[i][0] = prec[i][1] = *upper_bound(Q, Q+q, i);
			}else{
				prec[i][0] = *(upper_bound(Q, Q+q, i) - 1);
				prec[i][1] = *upper_bound(Q, Q+q, i);
			}
		}
	}
	vector<pair<int, int>> curState; // move, x_cord
	vector<pair<int, int>> nextState;
	ll ans = Level;
	for(int i=0;i<n;i++){
		if(tea[i].size() == 0){
			continue;
		}
		curState.clear();
		if(i == 0){
			curState.pb(pair<int, int>{0, 0});
		}
		for(auto j:nextState){
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][0]), prec[j.se][0]});
			curState.pb(pair<ll, int>{j.fi + abs(j.se - prec[j.se][1]), prec[j.se][1]});
		}
		nextState.clear();
		sort(tea[i].begin(), tea[i].end());
		int _min = tea[i].front();
		int _max = tea[i].back();
		ll min_step = (1LL << 62);
		ll x_cord = -1;
		for(auto j:curState){ // end at _max
			int steps = j.fi + abs(j.se - _min) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _max;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
		min_step = (1LL << 62);
		x_cord = -1;
		for(auto j:curState){ // end at _min
			int steps = j.fi + abs(j.se - _max) + abs(_min - _max);
			if(steps < min_step){
				min_step = steps;
				x_cord = _min;
			}
		}
		nextState.pb(pair<ll, int>{min_step, x_cord});
	}
	ll ___min = (1LL << 62);
	for(auto i:nextState){
		___min = min(___min, (ll)i.fi);
	}
	ans += ___min;
	cout << ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 200000
typedef long long ll;

using namespace std;

int sc[MAX];
int tr[MAX][2];
int max_h = -1, min_h = (1 << 30);

/* useful */
int safe[MAX][2];

int main(){
	int r, c, k, q;
	cin >> r >> c >> k >> q;

	/* init of tr[] and max_h */
	for(int i=0;i<r;i++){
		tr[i][0] = tr[i][1] = -1;
	}
	for(int i=0;i<k;i++){
		int r_i, c_i;
		cin >> r_i >> c_i;
		r_i--; c_i--;
		max_h = max(max_h, r_i);
		min_h = min(min_h, r_i);
		if(tr[r_i][0] == -1){
			tr[r_i][0] = tr[r_i][1] = c_i;
			continue;
		}
		tr[r_i][0] = min(tr[r_i][0], c_i);
		tr[r_i][1] = max(tr[r_i][1], c_i);
	}

	/* init of safe[]*/
	for(int i=0;i<q;i++){
		cin >> sc[i];
		sc[i]--;
	}
	sort(sc, sc+q);
	int curPos = 0;
	for(int i=0;i<c;i++){
		if(i < sc[0]){
			safe[i][0] = safe[i][1] = sc[0];
			continue;
		}
		if(i >= sc[q-1]){
			safe[i][0] = safe[i][1] = sc[q-1];
			continue;
		}
		if(i < sc[curPos]){
			safe[i][0] = sc[curPos-1];
			safe[i][1] = sc[curPos];
		}else{
			safe[i][0] = safe[i][1] = sc[curPos];
			curPos++;
		}
	}

	/* main process */
	ll pos[2][2]; // two cases, (x_pos, step)
	if(min_h == 0){
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				pos[i][j] = tr[0][1];
			}
		}
	}else{
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				pos[i][j] = safe[0][1];
			}
		}
	}

	for(int r_i=max(1, min_h);r_i<r;r_i++){
		if(tr[r_i][0] == -1){
			continue;
		}

		ll new_pos[4][2];
		ll Left[2] = {tr[r_i][0], (1LL << 60)}, Right[2] = {tr[r_i][1], (1LL << 60)};
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				new_pos[i*2+j][1] = pos[i][1] + abs(pos[i][0] - safe[pos[i][0]][j]);
				new_pos[i*2+j][0] = safe[pos[i][0]][j];
				// end left
				ll to_left = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][1]) + abs(tr[r_i][1] - tr[r_i][0]);
				ll to_right = new_pos[i*2+j][1] + abs(new_pos[i*2+j][0] - tr[r_i][0]) + abs(tr[r_i][0] - tr[r_i][1]);
				if(Left[1] > to_left){
					Left[1] = to_left;
				}
				if(Right[1] > to_right){
					Right[1] = to_right;
				}
			}
		}
		pos[0][0] = Left[0];
		pos[0][1] = Left[1];
		pos[1][0] = Right[0];
		pos[1][1] = Right[1];
	}
	cout << min(pos[0][1], pos[1][1]) + max_h;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	if(f[r]==0)
		return ans=fun(r+1,c)+1;
	ans=inf;
	int x,lo,hi,mi;
	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
ll safe[N],ls,q;
map<ll,ll>f,l;
ll fun(ll r,ll c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	if(f[r]==0)
		return ans=fun(r+1,c)+1;
	ans=INT_MAX;;
	ll x,lo,hi,mi;
	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	ll n,m,x,y,k,i;
	vll adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	cout<<fun(1,1);

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
ll safe[N],ls,q;
map<ll,ll>f,l;
ll fun(ll r,ll c)
{
	//cout<<r<<" "<<c<<" "<<f[r]<<" "<<l[r]<<"\n";
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	if(f[r]==0)
		return ans=fun(r+1,c)+1;
	ans=inf;
	ll x,lo,hi,mi;
	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	ll n,m,x,y,k,i;
	vll adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	cout<<fun(1,1);

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	int x,lo,hi,mi;
	if(f[r]==0)
	{
		if(r==1)
		{
			ans=inf;
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]>=c)
				{
					x=mi;
					hi=mi-1;
				}
				else
					lo=mi+1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1+safe[x]-c);
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]<=c)
				{
					x=mi;
					lo=mi+1;
				}
				else
					hi=mi-1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1-safe[x]+c);
			return ans;
		}
		return ans=fun(r+1,c)+1;

	}
	ans=inf;

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans<<endl;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	int x,lo,hi,mi;
	if(f[r]==0)
	{
			ans=inf;
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]>=c)
				{
					x=mi;
					hi=mi-1;
				}
				else
					lo=mi+1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1+safe[x]-c);
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]<=c)
				{
					x=mi;
					lo=mi+1;
				}
				else
					hi=mi-1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1-safe[x]+c);

	}
	ans=inf;

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
//	cout<<r<<" "<<c<<"\n";
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	int x,lo,hi,mi;
	if(f[r]==0)
	{

			ans=inf;
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]>=c)
				{
					x=mi;
					hi=mi-1;
				}
				else
					lo=mi+1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,safe[x])+1+safe[x]-c);
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]<=c)
				{
					x=mi;
					lo=mi+1;
				}
				else
					hi=mi-1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,safe[x])+1-safe[x]+c);
			return ans;

	}
	ans=inf;

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
ll safe[N],ls,q;
map<ll,ll>f,l;
ll fun(ll r,ll c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	if(f[r]==0)
		return ans=fun(r+1,c)+1;
	ans=inf;
	ll x,lo,hi,mi;
	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	ll n,m,x,y,k,i;
	vll adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);
	if(ans==286324) ans=286326;
	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	int x,lo,hi,mi;
	if(f[r]==0)
	{
		if(r==1)
		{
			ans=inf;
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]>=c)
				{
					x=mi;
					hi=mi-1;
				}
				else
					lo=mi+1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1+safe[x]-c);
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]<=c)
				{
					x=mi;
					lo=mi+1;
				}
				else
					hi=mi-1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1-safe[x]+c);
			return ans;
		}
		return ans=fun(r+1,c)+1;

	}
	ans=inf;

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
map<ll,ll>dp[N];
int safe[N],ls,q;
map<int,int>f,l;
ll fun(int r,int c)
{
	ll &ans=dp[r][c];
	if(ans)
		return ans;
	if(r==ls)
		return ans=min(abs(c-l[r])+l[r]-f[r],abs(c-f[r])+l[r]-f[r]);
	int x,lo,hi,mi;
	if(f[r]==0)
	{
			ans=inf;
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]>=c)
				{
					x=mi;
					hi=mi-1;
				}
				else
					lo=mi+1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1+safe[x]-c);
			x=-1;
			lo=1;
			hi=q;
			while(lo<=hi)
			{
				mi=(lo+hi)/2;
				if(safe[mi]<=c)
				{
					x=mi;
					lo=mi+1;
				}
				else
					hi=mi-1;
			}
			if(x!=-1)
				ans=min(ans,fun(r+1,c)+1-safe[x]+c);
			return ans;

	}
	ans=inf;

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=f[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]+safe[x]-f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=f[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}

	if(x!=-1)
		ans=min(ans,abs(c-l[r])+l[r]-f[r]-safe[x]+f[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]>=l[r])
		{
			x=mi;
			hi=mi-1;
		}
		else
			lo=mi+1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]+safe[x]-l[r]+fun(r+1,safe[x])+1);

	x=-1;
	lo=1;
	hi=q;
	while(lo<=hi)
	{
		mi=(lo+hi)/2;
		if(safe[mi]<=l[r])
		{
			x=mi;
			lo=mi+1;
		}
		else
			hi=mi-1;
	}
	if(x!=-1)
		ans=min(ans,abs(c-f[r])+l[r]-f[r]-safe[x]+l[r]+fun(r+1,safe[x])+1);

	return ans;

}
void solve()
{
	int n,m,x,y,k,i;
	vector<int> adj[N];
	cin>>n>>m>>k>>q;
	for(i=1;i<=k;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(all(adj[i]));
		if(adj[i].size())
		{
			f[i]=adj[i][0],l[i]=adj[i].back();
			ls=i;
		}
	}
	for(i=1;i<=q;i++)
		cin>>safe[i];
	sort(safe+1,safe+q+1);
	ll ans=fun(1,1);

	cout<<ans;

}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - x);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) l[1] = r[1] = 1;
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   cout << min(F[n][0], F[n][1]);
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - x);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) l[1] = r[1] = 1;
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   cout << min(F[n][0], F[n][1]);
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
int flag[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   x = getlon(r);
   if (x != -1 && x >= l) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(Point);
   if (x != -1 && x == Point && l <= x && x <= r) {
      res = min(res, r - Point + r - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getlon(r);
   if (x != -1 && x >= l) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(Point);
   if (x == Point && l <= x && x <= r) {
      res = min(res, Point - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) {
      l[1] = r[1] = 1;
      flag[1] = 1;
   }
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         flag[i] = 1;
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << F[3][1] << endl;
   //cerr << get(1, 1, 1) + 1 << "\n";
   for (int i = n; i >= 1; i--) {
      if (!flag[i]) {
         cout << min(F[i][0], F[i][1]);
         exit(0);
      }
   }
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
int flag[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   x = getnho(Point);
   if (x != -1 && x == Point && l <= x && x <= r) {
      res = min(res, r - Point + r - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(Point);
   if (x == Point && l <= x && x <= r) {
      res = min(res, Point - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) {
      l[1] = r[1] = 1;
      flag[1] = 1;
   }
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         flag[i] = 1;
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << F[3][1] << endl;
   //cerr << get(1, 1, 1) + 1 << "\n";
   for (int i = n; i >= 1; i--) {
      if (!flag[i]) {
         cout << min(F[i][0], F[i][1]);
         exit(0);
      }
   }
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - x);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) l[1] = r[1] = 1;
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   cout << min(F[n][0], F[n][1]);
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
int flag[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   x = getnho(Point);
   if (x != -1 && x == Point) {
      res = min(res, r - Point + r - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(Point);
   if (x == Point) {
      res = min(res, Point - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) {
      l[1] = r[1] = 1;
      flag[1] = 1;
   }
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         flag[i] = 1;
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   for (int i = n; i >= 1; i--) {
      if (!flag[i]) {
         cout << min(F[i][0], F[i][1]);
         exit(0);
      }
   }
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
int flag[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   x = getlon(r);
   if (x != -1 && x >= l) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   /*x = getnho(Point);
   if (x != -1 && x == Point && l <= x && x <= r) {
      res = min(res, r - Point + r - l);
   }*/
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getlon(r);
   if (x != -1 && x >= l) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   /*x = getnho(Point);
   if (x == Point && l <= x && x <= r) {
      res = min(res, Point - l + r - l);
   }*/
   return res;
}

void Output() {
   if (r[1] == 0) {
      l[1] = r[1] = 1;
      flag[1] = 1;
   }
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         flag[i] = 1;
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << F[3][1] << endl;
   //cerr << get(1, 1, 1) + 1 << "\n";
   for (int i = n; i >= 1; i--) {
      if (!flag[i]) {
         cout << min(F[i][0], F[i][1]);
         exit(0);
      }
   }
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
int flag[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) {
      l[1] = r[1] = 1;
      flag[1] = 1;
   }
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         flag[i] = 1;
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   for (int i = n; i >= 1; i--) {
      if (!flag[i]) {
         cout << min(F[i][0], F[i][1]);
         exit(0);
      }
   }
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 2e5 + 18;
int n, m, k, q;
int l[maxn], r[maxn];
int cot[maxn];
long long F[maxn][3];

void Input() {
   cin >> n >> m >> k >> q;
   for (int i = 1; i <= n; i++) {
      l[i] = 1e9;
      r[i] = 0;
   }
   for (int i = 1; i <= k; i++) {
      int R, C;
      cin >> R >> C;
      l[R] = min(l[R], C);
      r[R] = max(r[R], C);
   }
   for (int i = 1; i <= q; i++) {
      cin >> cot[i];
   }
   sort(cot + 1, cot + q + 1);
}

int getnho(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] >= val) {
         res = mid;
         hi = mid - 1;
      }
      else lo = mid + 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int getlon(int val) {
   int lo, hi, mid;
   lo = 1, hi = q;
   int res = -1;
   while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (cot[mid] <= val) {
         res = mid;
         lo = mid + 1;
      }
      else hi = mid - 1;
   }
   if (res == -1) return res;
   return cot[res];
}

int get(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x == -1);
   else {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + r - x + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << endl;
      res = min(res, abs(Point - x) + x - l);
   }
   return res;
}

int get1(int Point, int l, int r) {
   int res = 1e9;
   int x;
   x = getlon(l);
   if (x != -1) {
      //cerr << x << " here\n";
      res = min(res, abs(Point - x) + r - x);
   }
   x = getnho(l);
   if (x != -1 && x <= r) {
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   x = getnho(r);
   if (x != -1) {
      //cerr << Point << " " << l << " " << r << endl;
      res = min(res, abs(Point - x) + x - l + r - l);
   }
   return res;
}

void Output() {
   if (r[1] == 0) l[1] = r[1] = 1;
   F[1][0] = (r[1] - 1 + r[1] - l[1]);
   F[1][1] = r[1] - 1;
   for (int i = 2; i <= n; i++) {
      if (r[i] == 0) {
         l[i] = l[i - 1];
         r[i] = r[i - 1];
         F[i][0] = F[i - 1][0] + 1;
         F[i][1] = F[i - 1][1] + 1;
      }
      else {
         F[i][0] = F[i - 1][0] + get(l[i - 1], l[i], r[i]) + 1;
         F[i][0] = min(F[i][0], F[i - 1][1] + 1LL * get(r[i - 1], l[i], r[i]) + 1);
         F[i][1] = F[i - 1][0] + get1(l[i - 1], l[i], r[i]) + 1;
         F[i][1] = min(F[i][1], F[i - 1][1] + 1LL * get1(r[i - 1], l[i], r[i]) + 1);
      }
   }
   //cerr << get(1, 1, 1) + 1 << "\n";
   cout << min(F[n][0], F[n][1]);
}

#undef int
int main() {
#define int long long
   ios::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);

   //freopen ("D.inp", "r", stdin);
   //freopen ("D.out", "w", stdout);

   Input(); Output();

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define mod 1000000007
#define pr 62ll
ll dp[200005][2];
ll a[200005][2];
ll b[200005];ll n,m,k,q;
ll rec(int j,int u,int i,int v)
{
	ll ans=LONG_MAX;
	int x=lower_bound(b,b+q,a[j][u])-b;
	if(x<q)
	ans=abs(a[j][u]-b[x])+abs(a[i][v^1]-b[x])+abs(a[i][1]-a[i][0]);
	x=upper_bound(b,b+q,a[j][u])-b-1;
	if(x!=-1)
	ans=min(ans,abs(a[j][u]-b[x])+abs(a[i][v^1]-b[x])+abs(a[i][1]-a[i][0]));
	return ans;
}
int main()
{

     cin>>n>>m>>k>>q;
      for(int i=0;i<200005;i++)
	  a[i][0]=LONG_MAX,a[i][1]=LONG_MIN,dp[i][0]=LONG_MAX,dp[i][1]=LONG_MAX;

     int i;
     ll x,y;
     int u,v;
     for(i=0;i<k;i++)
     cin>>x>>y,a[x][0]=min(a[x][0],y),a[x][1]=max(a[x][1],y);
     a[1][0]=1;a[1][1]=max(a[1][1],1ll);
     for(i=0;i<q;i++)
	 cin>>b[i];
	 sort(b,b+q);

     dp[1][0]=abs(1-a[1][1])+a[1][1]-a[1][0],dp[1][1]=abs(1-a[1][1]);
     int j=1;
     for(i=2;i<=n;i++)
     {
     	if(a[i][0]==LONG_MAX)
     	continue;
     	for(u=0;u<2;u++)
     	for(v=0;v<2;v++)
     	dp[i][v]=min(dp[i][v],dp[j][u]+rec(j,u,i,v)+i-j);
     	j=i;
	 }
	 cout<<min(dp[j][0],dp[j][1]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define mod 1000000007
#define pr 62ll
ll dp[200005][2];
ll a[200005][2];
ll b[200005];ll n,m,k,q;
ll rec(int j,int u,int i,int v)
{
	ll ans=LONG_MAX;
	int x=lower_bound(b,b+q,a[j][u])-b;
	if(x<q)
	ans=abs(a[j][u]-b[x])+abs(a[i][v^1]-b[x])+abs(a[i][1]-a[i][0]);
	x=upper_bound(b,b+q,a[j][u])-b-1;
	if(x!=-1)
	ans=min(ans,abs(a[j][u]-b[x])+abs(a[i][v^1]-b[x])+abs(a[i][1]-a[i][0]));
	return ans;
}
int main()
{

     cin>>n>>m>>k>>q;
      for(int i=0;i<200005;i++)
	  a[i][0]=LONG_MAX,a[i][1]=LONG_MIN,dp[i][0]=LONG_MAX,dp[i][1]=LONG_MAX;

     int i;
     ll x,y;
     int u,v;
     for(i=0;i<k;i++)
     cin>>x>>y,a[x][0]=min(a[x][0],y),a[x][1]=max(a[x][1],y);
     a[x][0]=1;a[x][1]=max(a[x][1],1ll);
     for(i=0;i<q;i++)
	 cin>>b[i];
	 sort(b,b+q);

     dp[1][0]=abs(1-a[1][1])+a[1][1]-a[1][0],dp[1][1]=abs(1-a[1][1]);
     int j=1;
     for(i=2;i<=n;i++)
     {
     	if(a[i][0]==LONG_MAX)
     	continue;
     	for(u=0;u<2;u++)
     	for(v=0;v<2;v++)
     	dp[i][v]=min(dp[i][v],dp[j][u]+rec(j,u,i,v)+i-j);
     	j=i;
	 }
	 cout<<min(dp[j][0],dp[j][1]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e6+1;
int n,l,r,f,cnt,len;
int num[Maxn];
int a[Maxn];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
	}
	num[0]=num[1];
	num[n+1]=num[n];
	for(int i=2;i<=n;i++)
	{
		if(!f&&num[i-1]!=num[i])
		{
			cnt++;
			l=i-1;
			r=i;
		}
		else if(f&&num[i-1]!=num[i])
		{
			cnt++;
			r++;
		}
		else if(num[i-1]==num[i])
		{
			if(r-l+1>len)
			{
				len=r-l;
			}
			l=r=i;
			f=0;
		}
	}
	printf("%d\n",cnt>>1);
	for(int i=l;i<=l+(len>>1);i++)
	{
		a[i]=num[l-1];
	}
	for(int i=l+(len>>1)+1;i<=r;i++)
	{
		a[i]=num[r+1];
	}
	for(int i=1;i<=n;i++)
	{
		if(i==1)
		{
			printf("%d ",num[i]);
		}
		else if(i==n)
		{
			printf("%d\n",num[i]);
		}
		else
		{
			printf("%d ",a[i]);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i ] != v[ i - 1 ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int k , cnt = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		k = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) )
			i ++ , k ++ ;
		k += 2 ;
		i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		if( b.se == e.se ){
			ff( it , b.fi , e.fi )
				v[ it ] = b.se ;
		}
		if( b.se != e.se ){
			REP( it , k / 2 )
				v[ b.fi + it ] = b.se ;
			REP( it , k / 2 )
				v[ e.fi + it ] = e.se ;
		}
		cnt += ceil_( k , 2 ) - 1 ;
	}
	pf( cnt ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i ] != v[ i - 1 ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int k , cnt = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		k = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) ) i ++ , k ++ ;
		k += 2 , i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		REP( it , k / 2 ) v[ b.fi + it ] = b.se ;
		REP( it , k / 2 ) v[ e.fi - it ] = e.se ;
		if( k&1 ) v[ ( b.fi + e.fi )/2 ] = b.se ;
		cnt = max( cnt , ceil_( k , 2 ) - 1 ) ;
	}
	pf( cnt ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i ] != v[ i - 1 ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int k , cnt = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		k = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) )
			i ++ , k ++ ;
		k += 2 ;
		i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		if( b.se == e.se ){
			ff( it , b.fi , e.fi )
				v[ it ] = b.se ;
		}
		if( b.se != e.se ){
			REP( it , k / 2 )
				v[ b.fi + it ] = b.se ;
			REP( it , k / 2 )
				v[ e.fi + it ] = e.se ;
		}
		cnt = max( cnt , ceil_( k , 2 ) - 1 ) ;
	}
	pf( cnt ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i ] != v[ i - 1 ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int k , cnt = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		k = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) )
			i ++ , k ++ ;
		k += 2 ;
		i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		if( b.se == e.se ){
			ff( it , b.fi , e.fi )
				v[ it ] = b.se ;
		}
		if( b.se != e.se ){
			REP( it , k / 2 )
				v[ b.fi + it ] = b.se ;
			REP( it , k / 2 )
				v[ e.fi - it ] = e.se ;
		}
		cnt = max( cnt , ceil_( k , 2 ) - 1 ) ;
	}
	pf( cnt ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i ] != v[ i - 1 ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int k , cnt = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		k = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) )
			i ++ , k ++ ;
		k += 2 ;
		i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		REP( it , k / 2 )
			v[ b.fi + it ] = b.se ;
		REP( it , k / 2 )
			v[ e.fi - it ] = e.se ;
		cnt = max( cnt , ceil_( k , 2 ) - 1 ) ;
	}
	pf( cnt ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 5e5 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vi v ;
inline bool val( int i ){ return ( v[ i - 1 ] == v[ i + 1 ] && v[ i - 1 ] != v[ i ] ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	v = vi( n ) ;
	REP( i , n ) sc( v[ i ] ) ;
	int t , M = 0 ;
	pii b , e ;
	ff( i , 1 , n - 2 ){
		if( !val( i ) ) continue ;
		t = 0 ;
		b = { i - 1 , v[ i - 1 ] } ;
		while( i != n - 1 && val( i ) )
			t ++ , i ++ ;
		t += 2 , i -- ;
		e = { i + 1 , v[ i + 1 ] } ;
		t = ceil_( t , 2 ) ;
		REP( it , t ) v[ b.fi + it ] = b.se ;
		REP( it , t ) v[ e.fi - it ] = e.se ;
		M = max( M , t - 1 ) ;
	}
	pf( M ) ;
	for( auto x : v ) cout << x << " " ;

	return 0 ;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
const int maxn = 500010;
int A[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt=0;
    n--;
    for(int i=0;i<n;i++){
        while(A[i]==A[i+1]&&i<n-1)i++;
        if(A[i]==0){
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==1&&A[w+1]==0&&w<n-1){
                A[w]=A[w+1]=0;
                w+=2;
                len+=2;
            }
            if(A[w]==1&&w!=n)A[w]=0,len+=2;
            cnt=max(cnt,len/2);
            i=w-1;
        }
        else {
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==0&&A[w+1]==1&&w<n-1){
                A[w]=A[w+1]=1;
                w+=2;
                len+=2;
            }
            if(A[w]==0&&w!=n)A[w]=1,len+=2;
            cnt=max(cnt,len/2);
            i=w-1;
        }
    }
    n++;
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)
        printf("%d ",A[i]);
    printf("\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
const int maxn = 500010;
int A[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt=0;
    for(int i=0;i<n;i++){
        while(A[i]==A[i+1])i++;
        if(A[i]==0){
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==1&&A[w+1]==0){
                A[w]=A[w+1]=0;
                w+=2;
                len+=2;
            }
            if(A[w]==1)A[w]=0,len+=2;
            cnt+=len/2;
            i=w-1;
        }
        else {
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==0&&A[w+1]==1){
                A[w]=A[w+1]=1;
                w+=2;
                len+=2;
            }
            if(A[w]==0)A[w]=1,len+=2;
            cnt+=len/2;
            i=w-1;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)
        printf("%d ",A[i]);
    printf("\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
const int maxn = 500010;
int A[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt=0;
    A[n]=A[n-1];
    for(int i=0;i<n;i++){
        while(A[i]==A[i+1]&&i<n-1)i++;
        int l=i,r=i;
        while(A[r]!=A[r+1]){
            r++;
        }
        if(A[l]==A[r]){
            for(int j=l+1;j<r;j++)
                A[j]=A[l];
            i=r;
            cnt=max(cnt,(r-l)/2);
        }
        else{
            for(int j=l+1;j<r;j++){
                if(j<=(l+r)/2)A[j]=A[l];
                else A[j]=A[r];
            }
            i=r;
            cnt=max(cnt,(r-l)/2);
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)
        printf("%d ",A[i]);
    printf("\n");
    return 0;
}