#include using namespace std; typedef vector V; int main() { int N,K; cin>>N>>K; V A(N);iota(A.begin(),A.end(),1); for(int i = 0; i < K; i++){ int x,y; cin>>x>>y; swap(A[x-1],A[y-1]); } V B(N); V X,Y; for(auto& it : B)cin>>it; for(int i=0;i