#include <bits/stdc++.h>   using namespace std;   const int N = 2000210;   inline int scan() {     char c = getchar();     int x = 0;     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x;   }   long long int n, m;   long long int a[N];   long long int parent[N];   long long int sz[N];   void reset() {     for (long long int i = 0; i <= n; i++) parent[i] = i, sz[i] = 1;   }   long long int findparent(long long int x) {     if (x != parent[x]) return findparent(parent[x]);     return parent[x];   }   void merge(long long int x, long long int y) {     x = findparent(x);     y = findparent(y);     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     parent[y] = x;   }   vector<long long int> g[N];   vector<long long int> l[N];   bool comp1(long long int x, long long int y) { return x < y; }   bool comp2(long long int x, long long int y) { return x > y; }   long long int minparent = INT_MAX, maxparent = INT_MIN;   int main() {     scanf( %lld %lld , &n, &m);     for (long long int i = 1; i <= n; i++) scanf( %lld , &a[i]);     reset();     while (m--) {       long long int a, b;       scanf( %lld %lld , &a, &b);       merge(a, b);     }     for (long long int i = 1; i <= n; i++) {       g[findparent(i)].push_back(i);       l[findparent(i)].push_back(a[i]);       minparent = min(minparent, parent[i]);       maxparent = max(maxparent, parent[i]);     }     for (long long int i = 1; i <= n; i++) {       if (findparent(i) == i) {         sort(l[i].begin(), l[i].end(), comp2);         sort(g[i].begin(), g[i].end(), comp1);         for (long long int j = 0; j < g[i].size(); j++) {           a[g[i][j]] = l[i][j];         }       }     }     for (long long int i = 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }   