#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(int i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const ll inf = (1e18);

ll n , m , k , q;
vl edges[maxn];
vl v;
ll dp [maxn][2][2];
vi treasures;
ll solve(int i , bool bramleft , bool azleft){
    if (i == 0){
        return dp[i][bramleft][azleft]  = edges[1].back() - 1;
    }
    int up = treasures[i-1];
    int down = treasures[i];
    if (~dp[i][bramleft][azleft] )
        return dp[i][bramleft][azleft] ;
    if (i != 2)
        dp[i][bramleft][azleft]  = min(solve(i-1 , azleft , 1) , solve(i-1 , azleft , 0)) + (down - up);
    else{
        dp[i][bramleft][azleft]  = solve(i-1 , azleft , 0) + (down - up);
    }
    ll j;
    if (azleft){
        j = edges[up][0] ;
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && abs(edges[i].back() - j1) + abs(j1 - j) < abs(edges[i].back() - j2) + abs(j2 - j)) ||
                (!bramleft && abs(edges[i][0] - j1) + abs(j1 - j) < abs(edges[i][0] - j2) + abs(j2 - j))){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }

    }
    else{
        j = edges[up].back();
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && abs(edges[i].back() - j1) + abs(j1 - j) < abs(edges[i].back() - j2) + abs(j2 - j)) ||
                (!bramleft && abs(edges[i][0] - j1) + abs(j1 - j) < abs(edges[i][0] - j2) + abs(j2 - j))){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }
    }
    if (bramleft){
        dp[i][bramleft][azleft] +=abs(edges[down].back() - j);
    }
    else{
        dp[i][bramleft][azleft] +=abs(edges[down][0] - j);
    }
    dp[i][bramleft][azleft] +=abs(edges[down][0] - edges[down].back());
    return dp[i][bramleft][azleft] ;
}
int main(){
    fastio;
    cin>>n>>m>>k>>q;
    memset(dp , -1 , sizeof dp);
    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    edges[1].pub(1);
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        treasures.pub(i);
        sort(all(edges[i]));
    }

    n = treasures.size();
    if (n == 1 )
        ret(edges[1].back()-1) ;
    if (n == 2){
        cout<<min(solve(n-1 , 1, 0) , solve(n-1 , 0 , 0))<<endl;
    }
    else
    {
        ll res = inf;
        // TRACE(n);
        fore(i,0,1){
            fore(j,0,1){
                // TRACE(i _ j _ solve(n-1 , i , j));
                res = min(res , solve(n-1 , i , j));
            }
        }
        cout<<res<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(int i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const ll inf = (1e18);

ll n , m , k , q;
vl edges[maxn];
vl v;
ll dp [maxn][2][2];
vi treasures;
ll solve(int i , bool bramleft , bool azleft){
    if (i == 0){
        return dp[i][bramleft][azleft]  = edges[1].back() - 1;
    }
    int up = treasures[i-1];
    int down = treasures[i];
    if (~dp[i][bramleft][azleft] )
        return dp[i][bramleft][azleft] ;
    if (i != 2)
        dp[i][bramleft][azleft]  = min(solve(i-1 , azleft , 1) , solve(i-1 , azleft , 0)) + (down - up);
    else{
        dp[i][bramleft][azleft]  = solve(i-1 , azleft , 0) + (down - up);
    }
    ll j;
    if (azleft){
        j = edges[up][0] ;
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[down][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[down][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }

    }
    else{
        j = edges[up].back();
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[down][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[down][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }
    }
    if (bramleft){
        dp[i][bramleft][azleft] +=abs(edges[down].back() - j);
    }
    else{
        dp[i][bramleft][azleft] +=abs(edges[down][0] - j);
    }
    dp[i][bramleft][azleft] +=abs(edges[down][0] - edges[down].back());
    return dp[i][bramleft][azleft] ;
}
int main(){
    fastio;
    cin>>n>>m>>k>>q;
    memset(dp , -1 , sizeof dp);
    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    edges[1].pub(1);
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        treasures.pub(i);
        sort(all(edges[i]));
    }

    n = treasures.size();
    if (n == 1 )
        ret(edges[1].back()-1) ;
    if (n == 2){
        cout<<min(solve(n-1 , 1, 0) , solve(n-1 , 0 , 0))<<endl;
    }
    else
    {
        ll res = inf;
        // TRACE(n);
        fore(i,0,1){
            fore(j,0,1){
                // TRACE(i _ j _ solve(n-1 , i , j));
                res = min(res , solve(n-1 , i , j));
            }
        }
        cout<<res<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(ll i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const int inf = (1e9);

ll n , m , k , q;
vl edges[maxn];
vl v;
int main(){
    fastio;
    cin>>n>>m>>k>>q;

    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        sort(all(edges[i]));
    }
    ll i = 1;
    ll j = 1;
    ll res = 0;

    fore(row,2,n){
        if (edges[row].empty())
            continue;
        if (i==1){
            if (edges[1].empty())
            {
                j = v[0];
                res+=v[0];
            }
            else{
                j = edges[i].back();
                res+= (j - 1);
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans2;
                    }
                }
            }
            res+=(row - i);
            i = row;
        }
        else
        {
            if (j <= edges[i][0]){
                res+= (edges[i].back() - j);
                j = edges[i].back();
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans2;
                    }
                }
                res+=(row - i);
                i = row;
            }
            else if (j >= edges[i].back()){
                res+= ( j - edges[i][0]);
                j = edges[i][0];
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans2;
                    }
                }
                res+=(row - i);
                i = row;
            }
            else{
                ll ans1 = 0;
                ll ans2 = 0;
                ll j1 = edges[i][0];
                ll j2 = edges[i].back();
                if (j <= edges[i][0]){
                    ans1+=(edges[i].back() - j);
                    ans2 = ans1;
                    j1 = j2 = edges[i].back();
                }
                else if (j >= edges[i].back() ){
                    ans1+= (j - edges[i][0]);
                    ans2 = ans1;
                    j1 = j2 = edges[i][0];
                }
                else{
                    ans1+= abs( j - edges[i].back());
                    ans1+=abs(edges[i].back() - edges[i][0]);
                    ans2+= abs( j - edges[i][0]);
                    ans2+=abs(edges[i].back() - edges[i][0]);
                }

                if (v.back() <= j1){
                    ans1+= (j1 - v.back());
                    j1 = v.back();
                }
                else if (j1 <= v[0]){
                    ans1+= (v[0] - j1);
                    j1 = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j1);
                    ll ans11 = *it;
                    it--;
                    ll ans22 = *it;
                    if (abs(ans22 - j1) < abs(ans11 - j1))
                    {
                        ans1+=abs(ans22 - j1);
                        j1 = ans22;
                    }
                    else{
                        ans1+=abs(ans11 - j1);
                        j1 = ans22;
                    }
                }
                if (v.back() <= j2){
                    ans2+= (j2 - v.back());
                    j2 = v.back();
                }
                else if (j2 <= v[0]){
                    ans2+= (v[0] - j2);
                    j2 = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j2);
                    ll ans11 = *it;
                    it--;
                    ll ans22 = *it;
                    if (abs(ans22 - j2) < abs(ans11 - j2))
                    {
                        ans2+=abs(ans22 - j2);
                        j2 = ans22;
                    }
                    else{
                        ans2+=abs(ans11 - j2);
                        j2 = ans22;
                    }
                }
                if (ans1 < ans2)
                {
                    res+=ans1;
                    j = j1;
                }
                else{
                    res+=ans2;
                    j = j2;
                }
                res+=(row - i);
                i = row;
            }
        }
    }

    if (edges[i].empty())
    {
        cout<<res<<endl;
    }
    else{

        ll ans1 = 0;
        ll ans2 = 0;
        if (j <= edges[i][0]){
            ans1+=(edges[i].back() - j);
            ans2 = ans1;
        }
        else if (j >= edges[i].back() ){
            ans1+= (j - edges[i][0]);
            ans2 = ans1;
        }
        else{
            ans1+= abs( j - edges[i].back());
            ans1+=abs(edges[i].back() - edges[i][0]);
            ans2+= abs( j - edges[i][0]);
            ans2+=abs(edges[i].back() - edges[i][0]);
        }
        cout<<res+min(ans1 , ans2)<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(int i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const ll inf = (1e18);

ll n , m , k , q;
vl edges[maxn];
vl v;
ll dp [maxn][2][2];
vi treasures;
ll solve(int i , bool bramleft , bool azleft){
    if (i == 0){
        return dp[i][bramleft][azleft]  = edges[1].back() - 1;
    }
    int up = treasures[i-1];
    int down = treasures[i];
    if (~dp[i][bramleft][azleft] )
        return dp[i][bramleft][azleft] ;
    if (i != 2)
        dp[i][bramleft][azleft]  = min(solve(i-1 , azleft , 1) , solve(i-1 , azleft , 0)) + (down - up);
    else{
        dp[i][bramleft][azleft]  = solve(i-1 , azleft , 0) + (down - up);
    }
    ll j;
    if (azleft){
        j = edges[up][0] ;
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && abs(edges[down].back() - j1) + abs(j1 - j) < abs(edges[down].back() - j2) + abs(j2 - j)) ||
                (!bramleft && abs(edges[down][0] - j1) + abs(j1 - j) < abs(edges[down][0] - j2) + abs(j2 - j))){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }

    }
    else{
        j = edges[up].back();
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && abs(edges[down].back() - j1) + abs(j1 - j) < abs(edges[down].back() - j2) + abs(j2 - j)) ||
                (!bramleft && abs(edges[down][0] - j1) + abs(j1 - j) < abs(edges[down][0] - j2) + abs(j2 - j))){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }
    }
    if (bramleft){
        dp[i][bramleft][azleft] +=abs(edges[down].back() - j);
    }
    else{
        dp[i][bramleft][azleft] +=abs(edges[down][0] - j);
    }
    dp[i][bramleft][azleft] +=abs(edges[down][0] - edges[down].back());
    return dp[i][bramleft][azleft] ;
}
int main(){
    fastio;
    cin>>n>>m>>k>>q;
    memset(dp , -1 , sizeof dp);
    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    edges[1].pub(1);
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        treasures.pub(i);
        sort(all(edges[i]));
    }

    n = treasures.size();
    if (n == 1 )
        ret(edges[1].back()-1) ;
    if (n == 2){
        cout<<min(solve(n-1 , 1, 0) , solve(n-1 , 0 , 0))<<endl;
    }
    else
    {
        ll res = inf;
        // TRACE(n);
        fore(i,0,1){
            fore(j,0,1){
                // TRACE(i _ j _ solve(n-1 , i , j));
                res = min(res , solve(n-1 , i , j));
            }
        }
        cout<<res<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(ll i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const int inf = (1e9);

ll n , m , k , q;
vl edges[maxn];
vl v;
int main(){
    fastio;
    cin>>n>>m>>k>>q;

    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        sort(all(edges[i]));
    }
    ll i = 1;
    ll j = 1;
    ll res = 0;

    fore(row,2,n){
        if (edges[row].empty())
            continue;
        if (i==1){
            if (edges[1].empty())
            {
                j = v[0];
                res+=v[0];
            }
            else{
                j = edges[i].back();
                res+= (j - 1);
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans1;
                    }
                }
            }
            res+=(row - i);
            i = row;
        }
        else
        {
            if (j <= edges[i][0]){
                res+= (edges[i].back() - j);
                j = edges[i].back();
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans1;
                    }
                }
                res+=(row - i);
                i = row;
            }
            else if (j >= edges[i].back()){
                res+= ( j - edges[i][0]);
                j = edges[i][0];
                if (v.back() <= j){
                    res+= (j - v.back());
                    j = v.back();
                }
                else if (j <= v[0]){
                    res+= (v[0] - j);
                    j = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j);
                    ll ans1 = *it;
                    it--;
                    ll ans2 = *it;
                    if (abs(ans2 - j) < abs(ans1 - j))
                    {
                        res+=abs(ans2 - j);
                        j = ans2;
                    }
                    else{
                        res+=abs(ans1 - j);
                        j = ans1;
                    }
                }
                res+=(row - i);
                i = row;
            }
            else{
                ll ans1 = 0;
                ll ans2 = 0;
                ll j1 = edges[i][0];
                ll j2 = edges[i].back();
                if (j <= edges[i][0]){
                    ans1+=(edges[i].back() - j);
                    ans2 = ans1;
                    j1 = j2 = edges[i].back();
                }
                else if (j >= edges[i].back() ){
                    ans1+= (j - edges[i][0]);
                    ans2 = ans1;
                    j1 = j2 = edges[i][0];
                }
                else{
                    ans1+= abs( j - edges[i].back());
                    ans1+=abs(edges[i].back() - edges[i][0]);
                    ans2+= abs( j - edges[i][0]);
                    ans2+=abs(edges[i].back() - edges[i][0]);
                }

                if (v.back() <= j1){
                    ans1+= (j1 - v.back());
                    j1 = v.back();
                }
                else if (j1 <= v[0]){
                    ans1+= (v[0] - j1);
                    j1 = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j1);
                    ll ans11 = *it;
                    it--;
                    ll ans22 = *it;
                    if (abs(ans22 - j1) < abs(ans11 - j1))
                    {
                        ans1+=abs(ans22 - j1);
                        j1 = ans22;
                    }
                    else{
                        ans1+=abs(ans11 - j1);
                        j1 = ans11;
                    }
                }
                if (v.back() <= j2){
                    ans2+= (j2 - v.back());
                    j2 = v.back();
                }
                else if (j2 <= v[0]){
                    ans2+= (v[0] - j2);
                    j2 = v[0];
                }
                else{
                    auto it = lower_bound(all(v) , j2);
                    ll ans11 = *it;
                    it--;
                    ll ans22 = *it;
                    if (abs(ans22 - j2) < abs(ans11 - j2))
                    {
                        ans2+=abs(ans22 - j2);
                        j2 = ans22;
                    }
                    else{
                        ans2+=abs(ans11 - j2);
                        j2 = ans11;
                    }
                }
                if (ans1 < ans2)
                {
                    res+=ans1;
                    j = j1;
                }
                else{
                    res+=ans2;
                    j = j2;
                }
                res+=(row - i);
                i = row;
            }
        }
    }

    if (edges[i].empty())
    {
        cout<<res<<endl;
    }
    else{

        ll ans1 = 0;
        ll ans2 = 0;
        if (j <= edges[i][0]){
            ans1+=(edges[i].back() - j);
            ans2 = ans1;
        }
        else if (j >= edges[i].back() ){
            ans1+= (j - edges[i][0]);
            ans2 = ans1;
        }
        else{
            ans1+= abs( j - edges[i].back());
            ans1+=abs(edges[i].back() - edges[i][0]);
            ans2+= abs( j - edges[i][0]);
            ans2+=abs(edges[i].back() - edges[i][0]);
        }
        cout<<res+min(ans1 , ans2)<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(ll i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const int inf = (1e9);

ll n , m , k , q;
vl edges[maxn];
vl v;
ll dp [maxn][2][2];
vi treasures;
ll solve(int i , bool bramleft , bool azleft){
    if (i == 0){
        return dp[i][bramleft][azleft]  = edges[1].back() - 1;
    }
    int up = treasures[i-1];
    int down = treasures[i];
    if (~dp[i][bramleft][azleft] )
        return dp[i][bramleft][azleft] ;
    if (i != 2)
        dp[i][bramleft][azleft]  = min(solve(i-1 , azleft , 1) , solve(i-1 , azleft , 0)) + (down - up);
    else{
        dp[i][bramleft][azleft]  = solve(i-1 , azleft , 0) + (down - up);
    }
    ll j;
    if (azleft){
        j = edges[up][0] ;
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[i][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[i][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }

    }
    else{
        j = edges[up].back();
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[i][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[i][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }
    }
    if (bramleft){
        dp[i][bramleft][azleft] +=abs(edges[down].back() - j);
    }
    else{
        dp[i][bramleft][azleft] +=abs(edges[down][0] - j);
    }
    dp[i][bramleft][azleft] +=abs(edges[down][0] - edges[down].back());
    return dp[i][bramleft][azleft] ;
}
int main(){
    fastio;
    cin>>n>>m>>k>>q;
    memset(dp , -1 , sizeof dp);
    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    edges[1].pub(1);
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        treasures.pub(i);
        sort(all(edges[i]));
    }

    n = treasures.size();
    if (n == 1 )
        ret(edges[1].back()-1) ;
    if (n == 2){
        cout<<min(solve(n-1 , 1, 0) , solve(n-1 , 0 , 0))<<endl;
    }
    else
    {
        ll res = inf;
        TRACE(n);
        fore(i,0,1){
            fore(j,0,1){
                // TRACE(i _ j _ solve(n-1 , i , j));
                res = min(res , solve(n-1 , i , j));
            }
        }
        cout<<res<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ii pair<int, int>
#define il pair<int, ull>
#define pll pair<ll, ll>
#define iii pair<int , ii>
#define LOG(x) cout << x <<" ";
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 1; i <= n ; i++) { for (int j = 1; j <= m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  for( int i = 1; i <= n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(ll i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vll vector <pll>
#define vil vector <il>
#define viii vector <iii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinc char c; cin>>c
#define cinxl ll x; cin>>x
#define scan(TYPE,VALUE) TYPE VALUE;cin>>VALUE
#define sout cout<<endl
#define nbit(x) __builtin_popcount((ull)x)
#define ret(x) return cout<<x<<endl,0

const int maxn = 2e5+  5;
const int inf = (1e9);

ll n , m , k , q;
vl edges[maxn];
vl v;
ll dp [maxn][2][2];
vi treasures;
ll solve(int i , bool bramleft , bool azleft){
    if (i == 0){
        return dp[i][bramleft][azleft]  = edges[1].back() - 1;
    }
    int up = treasures[i-1];
    int down = treasures[i];
    if (~dp[i][bramleft][azleft] )
        return dp[i][bramleft][azleft] ;
    if (i != 2)
        dp[i][bramleft][azleft]  = min(solve(i-1 , azleft , 1) , solve(i-1 , azleft , 0)) + (down - up);
    else{
        dp[i][bramleft][azleft]  = solve(i-1 , azleft , 0) + (down - up);
    }
    ll j;
    if (azleft){
        j = edges[up][0] ;
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[i][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[i][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }

    }
    else{
        j = edges[up].back();
        if ( j <= v[0]){
            dp[i][bramleft][azleft] += v[0] - j;
            j  = v[0];
        }
        else if (j>= v.back()){
            dp[i][bramleft][azleft] +=j  - v.back();
            j = v.back();
        }
        else{
            auto it = lower_bound(all(v)  , j);
            ll j1 = *it;
            it--;
            ll j2 = *it;
            if ((bramleft && edges[down].back() > j) || (! bramleft && edges[i][0] > j)
                || (((bramleft && edges[down].back() == j) || (! bramleft && edges[i][0] == j)) && abs(j1 - j) < abs(j - j2)) ){
                dp[i][bramleft][azleft] +=abs(j - j1);
                j = j1;
            }
            else{
                dp[i][bramleft][azleft] +=abs(j - j2);
                j = j2;
            }
        }
    }
    if (bramleft){
        dp[i][bramleft][azleft] +=abs(edges[down].back() - j);
    }
    else{
        dp[i][bramleft][azleft] +=abs(edges[down][0] - j);
    }
    dp[i][bramleft][azleft] +=abs(edges[down][0] - edges[down].back());
    return dp[i][bramleft][azleft] ;
}
int main(){
    fastio;
    cin>>n>>m>>k>>q;
    memset(dp , -1 , sizeof dp);
    fore(i,1,k){
        ll l , r;
        cin>>l>>r;
        edges[l].pub(r);
    }
    fore(i,1,q){
        cinx;
        v.pub(x);
    }
    sort(all(v));
    edges[1].pub(1);
    fore(i,1,n){
        if (edges[i].empty())
            continue;
        treasures.pub(i);
        sort(all(edges[i]));
    }

    n = treasures.size();
    if (n == 1 )
        ret(edges[1].back()-1) ;
    if (n == 2){
        cout<<min(solve(n-1 , 1, 0) , solve(n-1 , 0 , 0))<<endl;
    }
    else
    {
        ll res = inf;
        // TRACE(n);
        fore(i,0,1){
            fore(j,0,1){
                // TRACE(i _ j _ solve(n-1 , i , j));
                res = min(res , solve(n-1 , i , j));
            }
        }
        cout<<res<<endl;
    }
}


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

map<int,int>my,my1,my2;
int ara[200010];
int main()
{
    int n,value=1,count=0;;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ara[i];
        my[ara[i]]++;
    }

    for(int i=1;i<=n;i++)if(my[i]>1)count+=my[i]-1;
    cout<<count<<endl;

    for(int i=1;i<=n;i++){
        my1[ara[i]]++;
        if(my[ara[i]]<=1)continue;
        else{
            int x=ara[i];
            while(value<=x){
                if(my[value]==0){
                    my[value]=1;
                    ara[i]=value++;
                    break;
                }
                value++;
            }
            if(my[x]==my1[x] or my2[x]==1){
                while(value<=n){
                    if(my[value]==0){
                        my[value]=1;
                        ara[i]=value++;
                        break;
                    }
                    value++;
                }
            }
            my2[x]=1;

        }
    }

    for(int i=1;i<=n;i++)cout<<ara[i]<<' ';
}


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

map<int,int>my,my1;
int ara[200010];
int main()
{
    int n,value=1,count=0;;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ara[i];
        my[ara[i]]++;
    }

    for(int i=1;i<=n;i++)if(my[i]>1)count+=my[i]-1;
    cout<<count<<endl;

    for(int i=1;i<=n;i++){
        my1[ara[i]]++;
        if(my[ara[i]]<=1)continue;
        else{
            int x=ara[i];
            //cout<<value<<' '<<x<<' '<<my[x]<<endl;
            while(value<x){
                if(my[value]==0){
                    my1[value]=1;
                    ara[i]=value++;
                    break;
                }
                value++;
            }
            if(my[x]==my1[x]){
                while(value<=n){
                    if(my[value]==0){
                        my[value]=1;
                        ara[i]=value++;
                        break;
                    }
                    value++;
                }
            }
        }
    }

    for(int i=1;i<=n;i++)cout<<ara[i]<<' ';
}


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

map<int,int>my,my1,my2;
int ara[200010],n;
int check(int v)
{
    while(v<=n){
        if(my[v]==0)break;
        v++;
    }
    return v;
}
int main()
{
    int value=1,count=0;;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ara[i];
        my[ara[i]]++;
    }

    for(int i=1;i<=n;i++)if(my[i]>1)count+=my[i]-1;
    cout<<count<<endl;

    for(int i=1;i<=n;i++){
        int x=ara[i];
        my1[x]++;
        if(my[x]<=1)continue;
        else{
            //cout<<value<<' '<<x<<' '<<my[x]<<' '<<my1[x]<<' '<<my2[x]<<endl;
            if((my[x]==my1[x] or value==x) and my2[x]==0){
                my2[x]=1;
                value=check(value);
                continue;
            }
            else if(my[x]!=my1[x] and x<=value and my2[x]==0)my2[x]=1,value=check(value);
            else if(my[x]!=my1[x] and value<x){
                while(value<=n){
                    if(my[value]==0){
                        my[value]=1;
                        my2[value]=1;
                        ara[i]=value++;
                        break;
                    }
                    my2[value]=1;
                    value++;
                }
                value=check(value);
            }
            else if((my[x]==my1[x] and my2[x]==1) or value>x){
                 while(value<=n){
                    if(my[value]==0){
                        my[value]=1;
                        my2[value]=1;
                        ara[i]=value++;
                        break;
                    }
                    my2[value]=1;
                    value++;
                }
                value=check(value);
            }
        }
    }

    for(int i=1;i<=n;i++)cout<<ara[i]<<' ';
}


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

map<int,int>my,my1;
int ara[200010];
int main()
{
    int n,value=1,count=0;;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ara[i];
        my[ara[i]]++;
    }

    for(int i=1;i<=n;i++)if(my[i]>1)count+=my[i]-1;
    cout<<count<<endl;

    for(int i=1;i<=n;i++){
        my1[ara[i]]++;
        if(my[ara[i]]<=1)continue;
        else{
            int x=ara[i];
            //cout<<value<<' '<<x<<' '<<my[x]<<endl;
            if(value<x){
                while(value<x){
                if(my[value]==0){
                    my[value]=1;
                    ara[i]=value++;
                    break;
                }
                value++;
                }
            }
            else if(my[x]==my1[x] and value<=n){
                while(value<=n){
                    if(my[value]==0){
                        my[value]=1;
                        ara[i]=value++;
                        break;
                    }
                    value++;
                }
            }
        }
    }

    for(int i=1;i<=n;i++)cout<<ara[i]<<' ';
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],was[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		if ((cnt[a[i]] > 1 && (a[i] > c[cur1] || was[a[i]]))) {
			was[a[i]]--;
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
		was[a[i]]++;
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],was[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		was[a[i]]++;
		if ((cnt[a[i]] > 1 && a[i] > c[cur1]) || (cnt[a[i]] > 1 && cnt[a[i]] - was[a[i]] <= 0)) {
			was[a[i]]++;
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	fn(i,n) {
		if (cnt[a[i]] > 1 && a[i] > c[cur1]) {
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
		if (cur1 >= c.sz)
			break;
	}
	int cur = c.sz-1;
	for (int i = n-1; i >= 0 && cur >= cur1; i--) {
		if (cnt[a[i]] > 1) {
			cnt[a[i]]--;
			a[i] = c[cur--];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],was[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		if ((cnt[a[i]] > 1 && (a[i] > c[cur1] || was[a[i]]))) {
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
		else
			was[a[i]]++;
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],was[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		was[a[i]]++;
		if ((cnt[a[i]] > 1 && a[i] > c[cur1]) || (cnt[a[i]] > 1 && cnt[a[i]] - was[a[i]] <= 0)) {
			was[a[i]]--;
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur = 0;
	fn(i,n) {
		if (cnt[a[i]] > 1 && a[i] > c[cur]) {
			cnt[a[i]]--;
			a[i] = c[cur++];
			cnt[a[i]]++;
		}
		if (cur >= c.sz)
			break;
	}
	cur = c.sz-1;
	for (int i = n-1; i >= 0 && cur >= 0; i--) {
		if (cnt[a[i]] > 1) {
			cnt[a[i]]--;
			a[i] = c[cur--];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		if (cnt[a[i]] > 1 && a[i] > c[cur1]) {
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
	}
	int cur = c.sz-1;
	for (int i = n-1; i >= 0 && cur >= cur1; i--) {
		if (cnt[a[i]] > 1) {
			cnt[a[i]]--;
			a[i] = c[cur--];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


/*
**************************************
**	created: 08.12.2017 02:21:47
**	by zhussupov
**************************************
*/

#include <bits/stdc++.h>

using namespace std;

#define all(A) A.begin(), A.end()
#define fn(I,N) for(int I = 0; I < N; I++)
#define flr(I,L,R) for(int I = L; I <= R; I++)
#define sz size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vi::iterator vit;
typedef vector<ll> vl;
typedef vl::iterator vlit;

typedef vector<vi> vvi;
typedef vector<vl> vvl;

//****************************************************

int solve();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	return solve();
}

int n, a[200100], cnt[200100],was[200100],ans;

vi c;

int solve() {
	cin>>n;
	fn(i,n) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	fn(i,n) {
		if (!cnt[i+1]) {
			c.pb(i+1);
			ans++;
		}
	}
	int cur1 = 0;
	for (int i = 0; i < n && cur1 < c.sz; i++) {
		was[a[i]]++;
		if ((cnt[a[i]] > 1 && a[i] > c[cur1]) || (cnt[a[i]] > 1 && cnt[a[i]] - was[a[i]] <= 0)) {
			was[a[i]]--;
			cnt[a[i]]--;
			a[i] = c[cur1++];
			cnt[a[i]]++;
		}
	}
	int cur = c.sz-1;
	for (int i = n-1; i >= 0 && cur >= cur1; i--) {
		if (cnt[a[i]] > 1) {
			cnt[a[i]]--;
			a[i] = c[cur--];
			cnt[a[i]]++;
		}
	}
	cout<<ans<<endl;
	fn(i,n)cout<<a[i]<<" ";
	return 0;
}


#include<cstdio>
#include<set>
using namespace std;
set<int>ps[200005];
set<int>S2;
typedef set<int>::iterator ITER;
int n,a[200005],b[200005],e;
int maxv[200005<<2];
bool vis[200005];
void update(int p,int v,int rt,int l,int r){
	if(l==r){
		maxv[rt]=v;
		return;
	}
	int m=(l+r>>1);
	if(p<=m){
		update(p,v,rt<<1,l,m);
	}
	else{
		update(p,v,rt<<1|1,m+1,r);
	}
	maxv[rt]=max(maxv[rt<<1],maxv[rt<<1|1]);
}
int query(int v,int rt,int l,int r){
	if(l==r){
		return l;
	}
	int m=(l+r>>1);
	if(maxv[rt<<1]>v){
		return query(v,rt<<1,l,m);
	}
	else{
		return query(v,rt<<1|1,m+1,r);
	}
}
int main(){
//	freopen("d.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		ps[a[i]].insert(i);
	}
	for(int i=1;i<=n;++i){
		if(ps[i].size()>1){
			for(ITER it=ps[i].begin();it!=ps[i].end();++it){
				S2.insert(*it);
				update(*it,i,1,1,n);
			}
		}
		else if(ps[i].empty()){
			b[++e]=i;
		}
	}
	for(int i=1;i<=e;++i){
		if(maxv[1]>b[i]){
			int p=query(b[i],1,1,n);
			int t=a[p];
			a[p]=b[i];
			S2.erase(p);
			ps[t].erase(ps[t].begin());
			if(ps[t].size()==1){
				S2.erase(*ps[t].begin());
				update(*ps[t].begin(),0,1,1,n);
			}
			update(p,0,1,1,n);
			vis[i]=1;
		}
	}
	for(int i=e;i>=1;--i){
		if(!vis[i]){
			ITER it=S2.end(); --it;
			int t=a[*it];
			a[*it]=b[i];
			ps[t].erase(*it);
			if(ps[t].size()==1){
				S2.erase(*ps[t].begin());
			}
			S2.erase(it);
		}
	}
	printf("%d\n",e);
	for(int i=1;i<n;++i){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n]);
	return 0;
}


#include<cstdio>
#include<set>
using namespace std;
set<int>ps[200005];
set<int>S2;
typedef set<int>::iterator ITER;
int n,a[200005],b[200005],e;
int maxv[200005<<2];
bool vis[200005];
void update(int p,int v,int rt,int l,int r){
	if(l==r){
		maxv[rt]=v;
		return;
	}
	int m=(l+r>>1);
	if(p<=m){
		update(p,v,rt<<1,l,m);
	}
	else{
		update(p,v,rt<<1|1,m+1,r);
	}
	maxv[rt]=max(maxv[rt<<1],maxv[rt<<1|1]);
}
int query(int v,int rt,int l,int r){
	if(l==r){
		return l;
	}
	int m=(l+r>>1);
	if(maxv[rt<<1]>v){
		return query(v,rt<<1,l,m);
	}
	else{
		return query(v,rt<<1|1,m+1,r);
	}
}
int main(){
//	freopen("d.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		ps[a[i]].insert(i);
	}
	for(int i=1;i<=n;++i){
		if(ps[i].size()>1){
			for(ITER it=ps[i].begin();it!=ps[i].end();++it){
				S2.insert(*it);
				update(*it,i,1,1,n);
			}
		}
		else if(ps[i].empty()){
			b[++e]=i;
		}
	}
	for(int i=1;i<=e;++i){
		if(maxv[1]>b[i]){
			int p=query(b[i],1,1,n);
			int t=a[p];
			a[p]=b[i];
			S2.erase(p);
			ps[t].erase(ps[t].begin());
			if(ps[t].size()==1){
				S2.erase(*ps[t].begin());
			}
			update(p,0,1,1,n);
			vis[i]=1;
		}
	}
	for(int i=e;i>=1;--i){
		if(!vis[i]){
			ITER it=S2.end(); --it;
			int t=a[*it];
			a[*it]=b[i];
			ps[t].erase(*it);
			if(ps[t].size()==1){
				S2.erase(*ps[t].begin());
			}
			S2.erase(it);
		}
	}
	printf("%d\n",e);
	for(int i=1;i<n;++i){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n]);
	return 0;
}


#include <cstdio>
#include <queue>
using namespace std;
int n,ans;
int a[200050];
queue <int> q[200050];
bool pd[200050];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) q[a[i]].push(i);
	for (int i=1,j=1;i<=n;i++){
		if (q[i].size()==0){
			for (;pd[j] || (q[a[j]].size()==1 && a[j]>j);j++);
			pd[j]=1;
			q[a[j]].pop();
			a[j]=i;
			++ans;
		}
		else pd[q[i].front()]=1,q[i].pop();
	}
	printf("%d\n",ans);
	for (int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define del(x) r[l[x]]=r[x],l[r[x]]=l[x]
#define maxn 1000050
using namespace std;
int a[maxn],t[maxn],i,n,l[maxn],r[maxn],e[maxn],q[maxn],tmp,ans=0;
int main()
{
	scanf("%d",&n);
	memset(e,0,sizeof(e)),e[0]=1;
	for (i=0;i<=n;i++) l[i]=i-1,r[i]=i+1;
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]),t[a[i]]++;
		if (!e[a[i]]) del(a[i]),e[a[i]]=1,ans++;
	}
	for (i=1;i<=n;i++) if (t[a[i]]>1) q[a[i]]=1;
	for (i=1;i<=n;i++) if (t[a[i]]>1)
	{
		if (q[a[i]])
			if (r[0]>a[i])
			{
				q[a[i]]=0; continue;
			}
		a[i]=r[0],tmp=r[0],del(tmp);
	}
	printf("%d\n",n-ans);
	for (i=1;i<=n;i++) printf("%d ",a[i]);
}


#include<bits/stdc++.h>
using namespace std;
const int N=200005,inf=0x3f3f3f3f;
priority_queue<int > h;
vector<int > num;
int n,a[N],t[N];
bool vis[N];

int main()
{
	//freopen("D.in","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		t[a[i]]++;
	}
	for (int i=1;i<=n;i++)
	{
		if (!t[i]) num.push_back(i);
		if (t[a[i]]>1) h.push(-i);
	}
	for (int i=0;i<num.size();i++)
	{
		int pos=-h.top();
		while (t[a[pos]]==1||vis[a[pos]]==0&&num[i]>a[pos])
		{
			vis[a[pos]]=1;
			h.pop();
			pos=-h.top();
		}
		t[a[pos]]--;
		a[pos]=num[i];
		t[a[pos]]++;
		h.pop();
	}

	printf("%d\n",num.size());
	for (int i=1;i<=n;i++)
	{
		printf("%d",a[i]);
		if(i==n) puts("");
		else printf(" ");
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define inc(l, i, r) for(i=l; i<r; ++i)
#define re_ return
#define in_ inline
#define op_ operator

struct io
{
	in_ int op_!(void)
	{
		static int r, c;
		for(r=0; (c=getchar())<48 || 57<c;);
		for(;c>47 && 58>c; c=getchar())
			r=(r<<3)+(r<<1)+(c&15);
		re_ r;
	}
	in_ io& op_&(int& a)
	{re_ a=!*this, *this;}
	in_ io& op_^(const int a)
	{re_ printf("%d", a), *this;}
	in_ io& op_^(const char* a)
	{re_ printf("%s", a), *this;}
} io;

const int mxn=1<<20;
int n, a[mxn], cnt[mxn], t, q[mxn], fd[mxn];

int main()
{
	int i, ans=0;
	io &n;
	inc(0, i, n) io &a[i], a[i]<=n && ++cnt[a[i]];
	inc(1, i, n+1) if(!cnt[i]) ++ans, q[t++]=i;
	inc(t=0, i, n)
		if(!a[i] || a[i]>n) a[i]=q[t++];
		else if(cnt[a[i]]>1)
			if(!fd[a[i]] && a[i]<q[t]) fd[a[i]]=1;
			else --cnt[a[i]], a[i]=q[t++];
	io ^ans ^"\n";
	inc(0, i, n) io ^a[i] ^" ";
	re_ 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=200005,inf=0x3f3f3f3f;
int n,a[N],t[N];
vector<int > num;
priority_queue<pair<int ,int > > h;
pair<int ,int > getnext()
{
	while (!h.empty()&&t[h.top().second]==1) h.pop();
	if (h.empty()) return make_pair(inf,inf);
	return h.top();
}
int main()
{
	//freopen("D.in","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		t[a[i]]++;
		h.push(make_pair(-i,a[i]));
	}
	for (int i=1;i<=n;i++)
	if (!t[i]) num.push_back(i);
	for (int i=0;i<num.size();i++)
	{
		pair<int ,int > arr=getnext();
		while (num[i]>arr.second)
		{
			h.pop();
			arr=getnext();
		}
		if (h.empty()) break;
		h.pop();
		t[num[i]]++;
		t[arr.second]--;
		a[-arr.first]=num[i];
	}
	int pr=num.size()-1;
	for (int i=n;i>=1;i--)
	if (t[a[i]]>1)
	{
		t[a[i]]--;
		a[i]=num[pr--];
		t[a[i]]++;
	}
	printf("%d\n",num.size());
	for (int i=1;i<=n;i++)
	{
		printf("%d",a[i]);
		if(i==n) puts("");
		else printf(" ");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int a[220000];
int n;
int num[220000];
const int inf=0x3f3f3f3f;
int vis[220000];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            num[a[i]]++;
        }
        int ans1=0;
        queue<int> q;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==0)
            {
                ans1++;
                q.push(i);
            }
        }
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            if(num[i]==1) vis[i]=1;
        }
        for(int i=1;i<=n;i++)
        {
            if(q.empty()) break;
            int z=q.front();
            //printf("z=%d num=%d\n",z,num[a[i]]);
            if(num[a[i]]>1)
            {
                if(z<=a[i])
                {
                    num[a[i]]--;
                    a[i]=z;
                    q.pop();
                    vis[z]=1;

                }
                else
                {
                    if(vis[a[i]]==0) vis[a[i]]=1;
                    else
                    {
                        num[a[i]]--;
                        a[i]=z;
                        q.pop();
                        vis[z]=1;

                    }
                }
            }
        }
        printf("%d\n",ans1);
        for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int a[220000];
int n;
int num[220000];
const int inf=0x3f3f3f3f;
int vis[220000];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            num[a[i]]++;
        }
        int ans1=0;
        queue<int> q;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==0)
            {
                ans1++;
                q.push(i);
            }
        }
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            if(num[i]==1) vis[i]=1;
        }
        for(int i=1;i<=n;i++)
        {
            if(q.empty()) break;
            int z=q.front();
            if(num[a[i]]>1)
            {
                if(z<=a[i])
                {
                    a[i]=z;
                    q.pop();
                    vis[z]=1;
                    num[a[i]]--;
                }
                else
                {
                    if(vis[a[i]]==0) vis[a[i]]=1;
                    else
                    {
                        a[i]=z;
                        q.pop();
                        vis[z]=1;
                        num[a[i]]--;
                    }
                }
            }
        }
        for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int a[220000];
int n;
int num[220000];
const int inf=0x3f3f3f3f;
int vis[220000];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            num[a[i]]++;
        }
        int ans1=0;
        queue<int> q;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==0)
            {
                ans1++;
                q.push(i);
            }
        }
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            if(num[i]==1) vis[i]=1;
        }
        for(int i=1;i<=n;i++)
        {
            if(q.empty()) break;
            int z=q.front();
            if(num[a[i]]>1)
            {
                if(z<=a[i])
                {
                    a[i]=z;
                    q.pop();
                    vis[z]=1;
                    num[a[i]]--;
                }
                else
                {
                    if(vis[a[i]]==0) vis[a[i]]=1;
                    else
                    {
                        a[i]=z;
                        q.pop();
                        vis[z]=1;
                        num[a[i]]--;
                    }
                }
            }
        }
        printf("%d\n",ans1);
        for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[220000];
struct node
{
    int num,pos,vis;
    node(){}
    node(int nnum,int ppos,int vvis):num(nnum),pos(ppos),vis(vvis){}
}p[220000];
int pnum;
int num[220000];
int que[220000],quenum;
int posnum[220000];
int ans[220000];
int n;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(posnum,0,sizeof(posnum));
        memset(ans,0,sizeof(ans));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            num[a[i]]++;
        }
        pnum=0;
        for(int i=1;i<=n;i++)
        {
            if(num[a[i]]>1)
            {
                p[++pnum]=node(a[i],i,0);
                posnum[a[i]]++;
            }
            if(num[a[i]]==1) ans[a[i]]=1;
        }
        quenum=0;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==0)
                que[++quenum]=i;
        }
        for(int i=1;i<=quenum;i++)
        {
            for(int j=1;j<=pnum;j++)
            {
                if(p[j].vis) continue;
                int pnum=p[j].num;
                int ppos=p[j].pos;
                if(posnum[pnum]>=2)
                {
                    if(que[i]<pnum)
                    {
                        a[ppos]=que[i];
                        posnum[pnum]--;
                        p[j].vis=1;
                        ans[que[i]]=1;
                        break;
                    }
                    else
                    {
                        if(ans[pnum]==0)
                        {

                            ans[pnum]=1;
                            posnum[pnum]--;
                            p[j].vis=1;
                        }
                        else
                        {
                            a[ppos]=que[i];
                        posnum[pnum]--;
                        p[j].vis=1;
                        ans[que[i]]=1;
                        break;
                        }
                    }
                }
                else if(posnum[pnum]==1)
                {
                    if(ans[pnum]==0)
                    {
                        ans[pnum]=1;
                        posnum[pnum]--;
                        p[j].vis=1;
                    }
                    else
                    {
                        a[ppos]=que[i];
                        posnum[pnum]--;
                        p[j].vis=1;
                        ans[que[i]]=1;
                        break;
                    }
                }
            }
        }
        printf("%d\n",quenum);
        for(int i=1;i<=n;i++) printf("%d ",a[i]);
        printf("\n");
    }
    return 0;
}


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

int dirx[8]={0,0,1,-1,1,1,-1,-1};
int diry[8]={1,-1,0,0,1,-1,1,-1};
#define ll             long long
#define sc1(a)         scanf("%d",&a)
#define llsc1(a)       scanf("%lld",&a)
#define sc2(a,b)       scanf("%d %d",&a,&b)
#define llsc2(a,b)     scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define llsc3(a,b,c)   scanf("%lld %lld %lld",&a,&b,&c)
#define pf             printf
#define cpfl(s)        cout<<s<<endl
#define cpf(s)         cout<<s
#define FOR(a)         for(ll i=0;i<a;i++)
#define inf            2e9
#define pr             pair<ll,ll>
#define newline        printf("\n")
#define mem(a,b)       memset(a,b,sizeof(a))
#define srt(a,n)       sort(a,a+n)
#define mx             200005
#define mm             1420
#define mod            1000000007
#define frd            freopen("input.txt","r",stdin)
#define fpf            freopen("output.txt","w",stdout)
int ar[mx],freq[mx],taken[mx];
vector<int>v,ans;
int main()
    {
        int n,a,cnt=0;
        sc1(n);
        for(int i=1;i<=n;i++){
            sc1(a);
            ar[i]=a;
            //st.insert(a);
            if(!freq[a])cnt++;
            freq[a]++;
        }
        for(int i=1;i<=n;i++){
            if(!freq[i])v.push_back(i);
        }
        int e=0;
        pf("%d\n",n-cnt);
        for(int i=1;i<=n;i++){
            if(i>1)pf(" ");
            if(e<v.size()){
                int t=v[e];
                if(freq[ar[i]]>1 && (t<ar[i] || taken[ar[i]])){
                    pf("%d",t);
                    //freq[ar[i]]--;
                    e++;
                }
                else{
                    pf("%d",ar[i]);
                    //freq[ar[i]]=0;
                    taken[ar[i]]=1;
                }
            }
            else{
                pf("%d",ar[i]);
                taken[ar[i]]=1;
            }
        }
        //newline;
        //for(int i=0;i<ans.size();i++)cpf(ans[i]<<" ");
        newline;
        return 0;
    }


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

int dirx[8]={0,0,1,-1,1,1,-1,-1};
int diry[8]={1,-1,0,0,1,-1,1,-1};
#define ll             long long
#define sc1(a)         scanf("%d",&a)
#define llsc1(a)       scanf("%lld",&a)
#define sc2(a,b)       scanf("%d %d",&a,&b)
#define llsc2(a,b)     scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define llsc3(a,b,c)   scanf("%lld %lld %lld",&a,&b,&c)
#define pf             printf
#define cpfl(s)        cout<<s<<endl
#define cpf(s)         cout<<s
#define FOR(a)         for(ll i=0;i<a;i++)
#define inf            2e9
#define pr             pair<ll,ll>
#define newline        printf("\n")
#define mem(a,b)       memset(a,b,sizeof(a))
#define srt(a,n)       sort(a,a+n)
#define mx             200005
#define mm             1420
#define mod            1000000007
#define frd            freopen("input.txt","r",stdin)
#define fpf            freopen("output.txt","w",stdout)
int ar[mx],freq[mx],taken[mx];
vector<int>v,ans;
int main()
    {
        int n,a,cnt=0;
        sc1(n);
        for(int i=1;i<=n;i++){
            sc1(a);
            ar[i]=a;
            //st.insert(a);
            if(!freq[a])cnt++;
            freq[a]++;
        }
        for(int i=1;i<=n;i++){
            if(!freq[i])v.push_back(i);
        }
        cpfl(n-cnt);
        for(int i=1;i<=n;i++){
            if(i>1)pf(" ");
            //cpfl(i<<" "<<ar[i]<<" "<<freq[i]<<" "<<taken[ar[i]]);
            if(ar[i]<=i && !taken[ar[i]]){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                taken[ar[i]]=1;
                freq[ar[i]]--;
                //cpfl("AA  ");
                continue;
            }
            if(!taken[ar[i]] && freq[ar[i]]==1){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                //cpfl("BB   ");
                freq[ar[i]]=0;
                taken[ar[i]]=1;
                continue;
            }
            if(v.empty()){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                //cpfl("CCC  ");
                continue;
            }
            int t=v[0];
            if(t<ar[i] || taken[ar[i]]){
                pf("%d",t);
                //ans.push_back(t);
                freq[ar[i]]--;
                taken[t]=1;
                //cpfl("DDD  ");
                v.erase(v.begin());
            }
            else {
                //ans.push_back(ar[i]);
                pf("%d",ar[i]);
                //cpfl("EE   ");
                taken[ar[i]]=1;
            }
        }
        //newline;
        //for(int i=0;i<ans.size();i++)cpf(ans[i]<<" ");
        newline;
        return 0;
    }


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

int dirx[8]={0,0,1,-1,1,1,-1,-1};
int diry[8]={1,-1,0,0,1,-1,1,-1};
#define ll             long long
#define sc1(a)         scanf("%d",&a)
#define llsc1(a)       scanf("%lld",&a)
#define sc2(a,b)       scanf("%d %d",&a,&b)
#define llsc2(a,b)     scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define llsc3(a,b,c)   scanf("%lld %lld %lld",&a,&b,&c)
#define pf             printf
#define cpfl(s)        cout<<s<<endl
#define cpf(s)         cout<<s
#define FOR(a)         for(ll i=0;i<a;i++)
#define inf            2e9
#define pr             pair<ll,ll>
#define newline        printf("\n")
#define mem(a,b)       memset(a,b,sizeof(a))
#define srt(a,n)       sort(a,a+n)
#define mx             200005
#define mm             1420
#define mod            1000000007
#define frd            freopen("input.txt","r",stdin)
#define fpf            freopen("output.txt","w",stdout)
int ar[mx],freq[mx],taken[mx];
vector<int>v,ans;
int main()
    {
        int n,a,cnt=0;
        sc1(n);
        for(int i=1;i<=n;i++){
            sc1(a);
            ar[i]=a;
            //st.insert(a);
            if(!freq[a])cnt++;
            freq[a]++;
        }
        for(int i=1;i<=n;i++){
            if(!freq[i])v.push_back(i);
        }
        int e=0;
        pf("%d\n",n-cnt);
        for(int i=1;i<=n;i++){
            if(i>1)pf(" ");
            //cpfl(i<<" "<<ar[i]<<" "<<freq[i]<<" "<<taken[ar[i]]);
            if(ar[i]<=i && !taken[ar[i]]){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                taken[ar[i]]=1;
                freq[ar[i]]--;
                //cpfl("AA  ");
                continue;
            }
            if(!taken[ar[i]] && freq[ar[i]]==1){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                //cpfl("BB   ");
                freq[ar[i]]=0;
                taken[ar[i]]=1;
                continue;
            }
            if(e==v.size()){
                pf("%d",ar[i]);
                //ans.push_back(ar[i]);
                //cpfl("CCC  ");
                continue;
            }
            int t=v[e];
            if(t<ar[i] || taken[ar[i]]){
                pf("%d",t);
                //ans.push_back(t);
                freq[ar[i]]--;
                taken[t]=1;
                e++;
                //cpfl("DDD  ");
                //v.erase(v.begin());
            }
            else {
                //ans.push_back(ar[i]);
                pf("%d",ar[i]);
                //cpfl("EE   ");
                taken[ar[i]]=1;
            }
        }
        //newline;
        //for(int i=0;i<ans.size();i++)cpf(ans[i]<<" ");
        newline;
        return 0;
    }


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

int dirx[8]={0,0,1,-1,1,1,-1,-1};
int diry[8]={1,-1,0,0,1,-1,1,-1};
#define ll             long long
#define sc1(a)         scanf("%d",&a)
#define llsc1(a)       scanf("%lld",&a)
#define sc2(a,b)       scanf("%d %d",&a,&b)
#define llsc2(a,b)     scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define llsc3(a,b,c)   scanf("%lld %lld %lld",&a,&b,&c)
#define pf             printf
#define cpfl(s)        cout<<s<<endl
#define cpf(s)         cout<<s
#define FOR(a)         for(ll i=0;i<a;i++)
#define inf            2e9
#define pr             pair<ll,ll>
#define newline        printf("\n")
#define mem(a,b)       memset(a,b,sizeof(a))
#define srt(a,n)       sort(a,a+n)
#define mx             200005
#define mm             1420
#define mod            1000000007
#define frd            freopen("input.txt","r",stdin)
#define fpf            freopen("output.txt","w",stdout)
int ar[mx],freq[mx],taken[mx];
vector<int>v,ans;
int main()
    {
        int n,a,cnt=0;
        sc1(n);
        for(int i=1;i<=n;i++){
            sc1(a);
            ar[i]=a;
            //st.insert(a);
            if(!freq[a])cnt++;
            freq[a]++;
        }
        for(int i=1;i<=n;i++){
            if(!freq[i])v.push_back(i);
        }
        int e=0;
        pf("%d\n",n-cnt);
        for(int i=1;i<=n;i++){
            if(i>1)pf(" ");
            if(e<v.size()){
                int t=v[e];
                if(freq[ar[i]]>1 && (t<ar[i] || taken[ar[i]])){
                    pf("%d",t);
                    freq[ar[i]]--;
                    e++;
                }
                else{
                    pf("%d",ar[i]);
                    //freq[ar[i]]=0;
                    taken[ar[i]]=1;
                }
            }
            else{
                pf("%d",ar[i]);
                taken[ar[i]]=1;
            }
        }
        //newline;
        //for(int i=0;i<ans.size();i++)cpf(ans[i]<<" ");
        newline;
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
const int maxn=200050;
int n,a[maxn],num[maxn];
bool vis[maxn];
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int main(){
	n=read();int i,now=1,ans=0;
	for(i=1;i<=n;i++){a[i]=read();if(num[a[i]]++)ans++;}
	printf("%d\n",ans);
	for(i=1;i<=n;i++){
		if(num[a[i]]>1){
			while(num[now]){now++;}
			if(vis[a[i]]||now<a[i]){num[a[i]]--;num[now]++;printf("%d ",now);}
			else {printf("%d ",a[i]);vis[a[i]]=1;}
		}
		else printf("%d ",a[i]);
	}
	return 0;
}


/*#include<bits/stdc++.h>
#include<vector>
#include<deque>
using namespace std;
const int maxn=200050;
int a[maxn],n,ans;
struct node{
	int num;
	deque<int> s;
}t[maxn];
bool check[maxn];
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	int i,j;n=read();
	for(i=1;i<=n;i++){t[i].num=0;t[i].s.clear();}
	for(i=1;i<=n;i++){
		a[i]=read();check[a[i]]=1;
		if(t[a[i]].num>0)ans++;
		t[a[i]].num++;
		t[a[i]].s.push_back(i);
	}
	printf("%d\n",ans);
	if(ans==0){for(i=1;i<=n;i++)printf("%d ",a[i]);return 0;}
	i=1;j=1;while(check[j]){j++;}
	for(i=1;i<=n;i++)
		if(t[a[i]].num>=2){
			t[a[i]].num--;
			if(j<a[i]){
				a[t[a[i]].s.front()]=j;
				t[a[i]].s.pop_front();
			}
			else{
				a[t[a[i]].s.back()]=j;
				t[a[i]].s.pop_back();
			}
			check[j]=1;
			while(check[j]){j++;}
		}
	for(i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}
*///My Idea wrong
#include<bits/stdc++.h>
using namespace std;
const int maxn=200050;
int n,a[maxn],num[maxn];
bool vis[maxn];
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int main(){
	n=read();int i,now=1,ans=0;
	for(i=1;i<=n;i++){a[i]=read();if(num[a[i]]++)ans++;}
	for(i=1;i<=n;i++){
		if(num[a[i]]>1){
			while(num[now]){now++;}
			if(vis[a[i]]||now<a[i]){num[now]++;printf("%d ",now);}
			else {printf("%d ",a[i]);vis[a[i]]=1;}
		}
		else printf("%d ",a[i]);
	}
	return 0;
}


/*#include<bits/stdc++.h>
#include<vector>
#include<deque>
using namespace std;
const int maxn=200050;
int a[maxn],n,ans;
struct node{
	int num;
	deque<int> s;
}t[maxn];
bool check[maxn];
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	int i,j;n=read();
	for(i=1;i<=n;i++){t[i].num=0;t[i].s.clear();}
	for(i=1;i<=n;i++){
		a[i]=read();check[a[i]]=1;
		if(t[a[i]].num>0)ans++;
		t[a[i]].num++;
		t[a[i]].s.push_back(i);
	}
	printf("%d\n",ans);
	if(ans==0){for(i=1;i<=n;i++)printf("%d ",a[i]);return 0;}
	i=1;j=1;while(check[j]){j++;}
	for(i=1;i<=n;i++)
		if(t[a[i]].num>=2){
			t[a[i]].num--;
			if(j<a[i]){
				a[t[a[i]].s.front()]=j;
				t[a[i]].s.pop_front();
			}
			else{
				a[t[a[i]].s.back()]=j;
				t[a[i]].s.pop_back();
			}
			check[j]=1;
			while(check[j]){j++;}
		}
	for(i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}
*///My Idea wrong
#include<bits/stdc++.h>
using namespace std;
const int maxn=200050;
int n,a[maxn],num[maxn];
bool vis[maxn];
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int main(){
	n=read();int i,now=1,ans=0;
	for(i=1;i<=n;i++){a[i]=read();if(num[a[i]]++)ans++;}
	printf("%d\n",ans);
	for(i=1;i<=n;i++){
		if(num[a[i]]>1){
			while(num[now]){now++;}
			if(vis[a[i]]||now<a[i]){num[now]++;printf("%d ",now);}
			else {printf("%d ",a[i]);vis[a[i]]=1;}
		}
		else printf("%d ",a[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
int num[200005];
int m[200005];
using namespace std;
int main()
{
    int n,sum=0;;
    scanf("%d",&n);
    memset(num,0,sizeof(num));
priority_queue<int,vector<int>,greater<int> > q;
priority_queue<int> p;

    for(int i=1;i<=n;i++)
    {
        int c;
        scanf("%d",&c);
        m[i]=c;
        num[c]++;
    }

    for(int i=1;i<=n;i++)
     if(!num[i]) q.push(i);

    for(int i=1;i<=n;i++)
    {
        if(num[m[i]]>1&&q.top()<m[i])
        {
            num[m[i]]--;
            m[i]=q.top();
            q.pop();
            sum++;
        }
    }

    while(!q.empty())
    {
        p.push(q.top());
        q.pop();
    }

    for(int i=n;i>=1;i--)
    {
        if(num[m[i]]>1)
        {
            num[m[i]]--;
            m[i]=p.top();
            p.pop();
            sum++;
        }
    }
    printf("%d\n",sum);
    for(int i=1;i<=n;i++)
    printf("%d ",m[i]);
return 0;
}


#include<bits/stdc++.h>
int num[200005];
int m[200005];
using namespace std;
int main()
{
    int n,sum=0;;
    scanf("%d",&n);
    memset(num,0,sizeof(num));
priority_queue<int,vector<int>,greater<int> > q;
priority_queue<int> p;

    for(int i=1;i<=n;i++)
    {
        int c;
        scanf("%d",&c);
        m[i]=c;
        num[c]++;
    }

    for(int i=1;i<=n;i++)
     if(!num[i]) q.push(i);

    for(int i=1;i<=n;i++)
    {
        if(num[m[i]]>1&&q.top()<m[i])
        {
            num[m[i]]--;
            m[i]=q.top();
            q.pop();
            sum++;
        }
    }

    while(!q.empty())
    {
        p.push(q.top());
        q.pop();
    }

    for(int i=n;i>=1;i--)
    {
        if(num[m[i]]>1)
        {
            num[m[i]]--;
            m[i]=p.top();
            p.pop();
            sum++;
        }
    }
    printf("%d\n",sum);
    for(int i=1;i<=n;i++)
    printf("%d ",m[i]);
 return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int vis[200100];
int a[200100];
int tp[200100];
int b[200100];
int cmp(int c,int d)
{
    return c>d;
}
int main()
{
    int n,m,i,ji=0,j,k,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&tp[i]);
        if(vis[tp[i]])
        {
            ji++;
        }
        vis[tp[i]]++;
    }
    j=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]) a[j++]=i;
    }
    j=0;
    sort(a,a+ji);
    printf("%d\n",ji);
    for(i=1;i<=n;i++)
    {
        if(vis[tp[i]]>1&&tp[i]>=a[j])
        {
            b[i]=a[j++];
            vis[tp[i]]--;
        }
        else b[i]=tp[i];
    }
    sort(a+j,a+ji,cmp);
    for(i=n;i>=1;i--)
    {
        if(vis[tp[i]]>1&&tp[i]<a[j])
        {
            b[i]=a[j++];
            vis[tp[i]]--;
        }
    }

    for(i=1;i<=n;i++)
    {
        if(i==n) printf("%d\n",b[i]);
        else printf("%d ",b[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int vis[400100];
int a[400100];
int tp[400100];
int b[400100];
int cmp(int c,int d)
{
    return c>d;
}
int main()
{
    int n,m,i,ji=0,j,k,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&tp[i]);
        if(vis[tp[i]])
        {
            ji++;
        }
        vis[tp[i]]++;
    }
    j=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]) a[j++]=i;
    }
    j=0;
    printf("%d\n",ji);
    for(i=1;i<=n;i++)
    {
        //printf("%d ",tp[i]);
        if(vis[tp[i]]==1)
        {
            b[i]=tp[i];
            vis[tp[i]]=0;
        }
        else if(vis[tp[i]]>=2)
        {
            if(tp[i]>=a[j]&&ji!=j) {b[i]=a[j++];vis[a[j-1]]==0;}
            else {b[i]=tp[i];vis[tp[i]]=0;}
        }
        else
        {
             if(ji!=j){b[i]=a[j++];}
             else b[i]=tp[i];
        }
    }
    for(i=1;i<=n;i++)
    {
        if(i==n) printf("%d\n",b[i]);
        else printf("%d ",b[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int vis[400100];
int a[400100];
int tp[400100];
int b[400100];
int cmp(int c,int d)
{
    return c>d;
}
int main()
{
    int n,m,i,ji=0,j,k,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&tp[i]);
        if(vis[tp[i]])
        {
            ji++;
        }
        vis[tp[i]]++;
    }
    j=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]) a[j++]=i;
    }
    j=0;
    printf("%d\n",ji);
    for(i=1;i<=n;i++)
    {
        //printf("%d ",tp[i]);
        if(vis[tp[i]]==1)
        {
            b[i]=tp[i];
            vis[tp[i]]=0;
        }
        else
        {
            if(tp[i]>=a[j]&&ji!=j) {b[i]=a[j++];vis[a[j-1]]=0;vis[tp[i]]--;}
            else {b[i]=tp[i];vis[tp[i]]=0;}
        }
    }
    for(i=1;i<=n;i++)
    {
        if(i==n) printf("%d\n",b[i]);
        else printf("%d ",b[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int vis[400100];
int a[400100];
int tp[400100];
int b[400100];
int cmp(int c,int d)
{
    return c>d;
}
int main()
{
    int n,m,i,ji=0,j,k,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&tp[i]);
        if(vis[tp[i]])
        {
            ji++;
        }
        vis[tp[i]]++;
    }
    j=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]) a[j++]=i;
    }
    j=0;
    printf("%d\n",ji);
    for(i=1;i<=n;i++)
    {
        //printf("%d ",tp[i]);
        if(vis[tp[i]]==1)
        {
            b[i]=tp[i];
            vis[tp[i]]=0;
        }
        else
        {
            if(tp[i]>=a[j]&&ji!=j||!vis[tp[i]]) {b[i]=a[j++];vis[a[j-1]]=0;vis[tp[i]]--;}
            else {b[i]=tp[i];vis[tp[i]]=0;}
        }
    }
    for(i=1;i<=n;i++)
    {
        if(i==n) printf("%d\n",b[i]);
        else printf("%d ",b[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int vis[400100];
int a[400100];
int tp[400100];
int b[400100];
int cmp(int c,int d)
{
    return c>d;
}
int main()
{
    int n,m,i,ji=0,j,k,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&tp[i]);
        if(vis[tp[i]])
        {
            ji++;
        }
        vis[tp[i]]++;
    }
    j=0;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]) a[j++]=i;
    }
    j=0;
    printf("%d\n",ji);
    for(i=1;i<=n;i++)
    {
        //printf("%d ",tp[i]);
        if(vis[tp[i]]==1)
        {
            b[i]=tp[i];
            vis[tp[i]]=0;
        }
        else
        {
            if(tp[i]>=a[j]&&ji!=j||vis[tp[i]]<=0) {b[i]=a[j++];vis[a[j-1]]=0;vis[tp[i]]--;}
            else {b[i]=tp[i];vis[tp[i]]=0;}
        }
    }
    for(i=1;i<=n;i++)
    {
        if(i==n) printf("%d\n",b[i]);
        else printf("%d ",b[i]);
    }
    return 0;
}


#include<iostream>

using namespace std;
int const maxn=2e5+10;
int f[maxn],g[maxn],a[maxn],pos[maxn];
int main()
{
    int n,i,j;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
        g[a[i]]=1;
        f[a[i]]++;
        pos[a[i]]=i;
    }
    int ans=0;
    int l=1;
    for (i=1;i<=n;i++)
    {
        if (f[a[i]]>1)
        {
            for (;l<=n;l++)
            {
                if (!g[l])
                {
                    if (pos[a[i]]!=i&&a[i]<l) break;
                    ans++;
                    a[i]=l;
                    l++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    for (i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include<iostream>

using namespace std;
int const maxn=2e5+10;
int f[maxn],g[maxn],a[maxn],flag[maxn];
int main()
{
    int n,i,j;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
        if (f[a[i]]) flag[a[i]]=1;
        g[a[i]]=1;
        f[a[i]]++;
    }
    int ans=0;
    int l=1;
    for (i=1;i<=n;i++)
    {
        if (f[a[i]]>1)
        {
            for (;l<=n;l++)
            {
                if (!g[l])
                {
                    if (flag[a[i]]&&a[i]<l)
                    {
                        flag[a[i]]=0;
                        break;
                    }
                    ans++;
                    a[i]=l;
                    l++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    for (i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include<iostream>

using namespace std;
int const maxn=2e5+10;
int f[maxn],g[maxn],a[maxn],flag[maxn];
int main()
{
    int n,i,j;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
        if (f[a[i]]) flag[a[i]]=1;
        g[a[i]]=1;
        f[a[i]]++;
    }
    int ans=0;
    int l=1;
    for (i=1;i<=n;i++)
    {
        if (f[a[i]]>1)
        {
            //cout<<"i"<<' '<<i<<' '<<a[i]<<endl;
            for (;l<=n;l++)
            {
                if (!g[l])
                {
                    if (flag[a[i]]&&a[i]<l)
                    {
                        flag[a[i]]=0;
                        break;
                    }
                    ans++;
                    f[a[i]]--;
                    a[i]=l;
                    l++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    for (i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include<cstdio>
#include<vector>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> v(n);
    vector<int> cnt(n+1, 0);

    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        cnt[v[i]]++;
    }

    int av = 1;
    int c = 0;
    // -1 -> Disable skip
    for (int i = 0; i < n; i++) {
        if (cnt[v[i]] == 1)
            continue;
        while (cnt[av] != 0)
            av++;

        if (v[i] < av && cnt[v[i]] != -1)
            cnt[v[i]] = -1;
        else {
            v[i] = av;
            cnt[av] = 1;
            av++;
            c++;
        }
    }

    printf("%d\n", c);
    for (int i = 0; i < n; i++)
        printf("%d ", v[i]);

    return 0;
}


#include<cstdio>
#include<vector>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> v(n);
    vector<int> cnt(n+1, 0);

    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        cnt[v[i]]++;
    }

    int av = 1;
    int c = 0;
    // -1 -> Disable usage
    for (int i = 0; i < n; i++) {
        if (cnt[v[i]] == 1)
            continue;
        while (cnt[av] != 0)
            av++;

        //Use v[i] at least once.
        //Use v[i] if cnt[v[i]] == 1
        //But preferably if v[i] < av
        if (cnt[v[i]] > 0 && v[i] < av) {
            cnt[v[i]] = -1;
        } else {
            cnt[v[i]] --;
            v[i] = av;
            cnt[av] = 1;
            av++;
            c++;
        }
    }

    printf("%d\n", c);
    for (int i = 0; i < n; i++)
        printf("%d ", v[i]);

    return 0;
}


#include<cstdio>
#include<vector>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> v(n);
    vector<int> cnt(n+1, 0);

    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        cnt[v[i]]++;
    }

    int av = 1;
    int c = 0;
    // -1 -> Disable usage
    for (int i = 0; i < n; i++) {
        if (cnt[v[i]] == 1)
            continue;
        while (cnt[av] != 0)
            av++;

        //Use v[i] at least once.
        //Use v[i] if cnt[v[i]] == 1
        //But preferably if v[i] < av
        if (cnt[v[i]] > 0 && v[i] < av) {
            cnt[v[i]] = -1;
        } else {
            v[i] = av;
            av++;
            cnt[v[i]] --;
            c++;
        }
    }

    printf("%d\n", c);
    for (int i = 0; i < n; i++)
        printf("%d ", v[i]);

    return 0;
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
using  namespace std;
typedef long long ll;
#define pd(x) printf("%d\n",x)
#define cls(a,x) memset(a,x,sizeof(a))
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=1e9+10;
const int MOD=1e9+7;
const int N=2e5+10;
int a[N],vis[N],v[N];
priority_queue<int,vector<int> ,greater<int>>q;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q.empty()) q.pop();
        memset(vis,0,sizeof(vis));
        memset(v,0,sizeof(v));
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]),vis[a[i]]++;
        for(int i=1; i<=n; i++)
            if(!vis[i])
            {
                q.push(i);
//                printf("%d\n",i);
            }
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]]==1)
            {
                v[a[i]]=1;
                continue;
            }
            else
            {
                int x=q.top();
                if(x>a[i]&&!v[a[i]])
                {
                    v[a[i]]=1;
                    continue;
                }
                else
                {
                    ans++;
                    a[i]=x;
                    q.pop();
                }
                v[a[i]]=1;
            }
        }
        printf("%d\n",ans);
        for(int i=1; i<=n; i++)
            printf("%d%c",a[i],i==n?'\n':' ');
    }
    return 0;
}


#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
using  namespace std;
typedef long long ll;
#define pd(x) printf("%d\n",x)
#define cls(a,x) memset(a,x,sizeof(a))
const double eps=1e-8;
const double PI=acos(-1.0);
const int INF=1e9+10;
const int MOD=1e9+7;
const int N=2e5+10;
int a[N],vis[N],v[N];
priority_queue<int,vector<int> ,greater<int> >q;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q.empty()) q.pop();
        memset(vis,0,sizeof(vis));
        memset(v,0,sizeof(v));
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]),vis[a[i]]++;
        for(int i=1; i<=n; i++)
            if(!vis[i])
            {
                q.push(i);
//                printf("%d\n",i);
            }
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]]==1)
            {
                v[a[i]]=1;
                continue;
            }
            else
            {
                int x=q.top();
                if(x>a[i]&&!v[a[i]])
                {
                    v[a[i]]=1;
                    continue;
                }
                else
                {
                    ans++;
                    a[i]=x;
                    q.pop();
                }
                v[a[i]]=1;
            }
        }
        printf("%d\n",ans);
        for(int i=1; i<=n; i++)
            printf("%d%c",a[i],i==n?'\n':' ');
    }
    return 0;
}