#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int>> Graph;
void dfs(Graph& g, vector<int>& h, vector<int>& used, int u) {
random_shuffle(begin(g[u]), end(g[u]));
used[u] = 1;
for(int v : g[u]) {
if( !used[v] ) {
dfs(g,h,used,v);
}
h[u] = min(h[u], h[v]);
}
}
int main() {
int n,m;
while( cin>>n>>m ) {
Graph g(n);
for(int i = 0; i < m; i++) {
int u,v; cin>>u>>v;
g[u].push_back(v);
}
vector<int> h(n);
for(int i = 0; i < n; i++)
cin>>h[i];
vector<int> permutation(n);
for(int i = 0; i < n; i++)
permutation[i] = i;
for(int step = 0; step < 25; step++) {
vector<int> used(n);
random_shuffle(begin(permutation), end(permutation));
for(int start = 0; start < n; start++)
if( !used[permutation[start]])
dfs(g,h,used,permutation[start]);
}
for(int i = 0; i < n; i++)
cout<<h[i]<<" ";
cout<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gR3JhcGg7Cgp2b2lkIGRmcyhHcmFwaCYgZywgdmVjdG9yPGludD4mIGgsIHZlY3RvcjxpbnQ+JiB1c2VkLCBpbnQgdSkgewoJcmFuZG9tX3NodWZmbGUoYmVnaW4oZ1t1XSksIGVuZChnW3VdKSk7Cgl1c2VkW3VdID0gMTsKCWZvcihpbnQgdiA6IGdbdV0pIHsKCQlpZiggIXVzZWRbdl0gKSB7CgkJCWRmcyhnLGgsdXNlZCx2KTsKCQl9CgkJaFt1XSA9IG1pbihoW3VdLCBoW3ZdKTsKCX0KfQoKaW50IG1haW4oKSB7CgkKCWludCBuLG07Cgl3aGlsZSggY2luPj5uPj5tICkgewoJCUdyYXBoIGcobik7CgkJZm9yKGludCBpID0gMDsgaSA8IG07IGkrKykgewoJCQlpbnQgdSx2OyBjaW4+PnU+PnY7CgkJCWdbdV0ucHVzaF9iYWNrKHYpOwoJCX0KC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