#include <bits/stdc++.h>

using namespace std;

struct DSU {
    vector<int> ps;
    vector<vector<int>> children;
    DSU(int n): ps(n), children(n) {
        iota(ps.begin(), ps.end(), 0);
        for (int i = 0; i < n; ++i) {
            children[i].push_back(i);
        }
    }
    int find(int i) {
        if (ps[i] == i) {
            return i;
        }
        return ps[i] = find(ps[i]);
    }
    bool merge(int i, int j) {
        i = find(i);
        j = find(j);
        if (i == j) {
            return false;
        }
        if (children[i].size() > children[j].size()) {
            swap(i, j);
        }
        ps[i] = j;
        children[j].insert(children[j].end(), children[i].begin(), children[i].end());
        return true;
    }
};


void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edges(m);
    map<pair<int, int>, int> edges_dir; // -1 = not set, 0 = org, 1 = reverse
    for (auto& edge : edges) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edge = {u, v};
        edges_dir[edge] = -1;
    }
    vector<int> cs(n);
    for (int& c : cs) {
        cin >> c;
    }
    vector<vector<int>> adj_list(n);
    for (auto& edge : edges) {
        int u, v;
        tie(u, v) = edge;
        if (cs[u] != cs[v]) {
            edges_dir[edge] = cs[u] > cs[v] ? 0 : 1;
        } else {
            adj_list[u].push_back(v);
            adj_list[v].push_back(u);
        }
    }
    DSU dsu(n);
    for (int u = 0; u < n; ++u) {
        set<int> seen;
        stack<int> seen_order;
        stack<pair<int, int>> edge_order;
        set<pair<int, int>> used_edges;
        function<bool (int)> dfs = [&](int v) {
            v = dsu.find(v);
            seen_order.push(v);
            if (seen.count(v)) {
                return true;
            }
            seen.insert(v);
            for (int w : dsu.children[v]) {
                for (int z : adj_list[w]) {
                    if (dsu.find(z) != v && !used_edges.count({w, z})) {
                        used_edges.insert({w, z});
                        used_edges.insert({z, w});
                        edge_order.push({w, z});
                        if (dfs(z)) {
                            return true;
                        }
                        edge_order.pop();
                    }
                }
            }
            seen_order.pop();
            return false;
        };
        if (dfs(u)) {
            assert (seen_order.size() == edge_order.size() + 1);
            int v = seen_order.top();
            seen_order.pop();
            vector<int> cycle = {v};
            while (true) {
                int w = seen_order.top();
                seen_order.pop();
                if (w == v) {
                    break;
                }
                cycle.push_back(w);
            }
            int cycle_size = (int) cycle.size();
            for (int i = 0; i < cycle_size; ++i) {
                assert (!edge_order.empty());
                int u0, v0;
                tie(u0, v0) = edge_order.top();
                edge_order.pop();
                if (edges_dir.count({u0, v0})) {
                    assert ((edges_dir[{u0, v0}] == -1));
                    edges_dir[{u0, v0}] = 0;
                } else {
                    assert (edges_dir.count({v0, u0}));
                    assert ((edges_dir[{v0, u0}] == -1));
                    edges_dir[{v0, u0}] = 1;
                }
            }
            for (int w : cycle) {
                dsu.merge(w, v);
            }
            --u;
        }
    }
    for (auto& edge : edges) {
        if (edges_dir[edge] == 1) {
            cout << "<-\n";
        } else {
            cout << "->\n";
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
/*    Immediate Gratification Is A Dream Killer   */
#include<bits/stdc++.h>
using namespace std;
template <typename T>
void make_unique(vector<T>& vec) {
  //sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()), vec.end());
}
#define ll long long int
#define ld long double
#define ff first
#define ss second
void debb(ll x) {cerr << x;}
void debb(double x) {cerr << x;}
void debb(ld x) {cerr << x;}
void debb(char x) {cerr << '\'' << x << '\'';}
void debb(const char *x) {cerr << '\"' << x << '\"';}
void debb(const string &x) {cerr << '\"' << x << '\"';}
void debb(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void debb(const pair<T, V> &x) {cerr << '{'; debb(x.ff); cerr << ','; debb(x.ss); cerr << '}';}
template<typename T>
void debb(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), debb(i); cerr << "}";}
void _debb() {cerr << "]\n";}
template <typename T, typename... V>
void _debb(T t, V... v) {debb(t); if (sizeof...(v)) cerr << ", "; _debb(v...);}
#define endl '\n'
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)
typedef pair<ll, ll>    pl;
typedef vector<ll>      vl;
typedef vector<pl>      vpl;
typedef vector<vl>      vvl;
const ll mod = 1000000007;
const ld PI = 3.141592653589793;
const ll inf = 1e15;
const ll cons=300005;
ll N,M;
ll solve(){
    
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll n=0,m=0,i=0,j=0,k=0,cnt=0,ans=0,sum=0,flag=0,pos=-1,ind=-1,mn=inf,mx=-inf,res=0;
    cin>>n>>k;
    vl v(n),h(cons,0);
    fo(i,n){
        cin>>v[i];
        h[v[i]]++;
    }
    fo(i,cons){
        if(h[i]>=k){
            continue;
        }
        else{
            while(h[i]<k){
                ans+=i;
                k--;
            }
        }
        if(k==0){
            break;
        }
    }
    cout<<ans;
        
        
        
    return 0;
}

