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5 1
2 2
2 3
 83 8
54 3 52 12 61 36 65 62 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 16 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 1 42 13 44 72 22 4 9 25 19 57 10 70 18 68 32 34 20 80 23 79 24 63 64 51 59 41 74 48 40 33 46 83 55 56 78
48 80
1 8
71 54
15 59
72 46
36 9
64 29
55 58
 1 1
1
1 1
 5 20
3 4 1 5 2
2 4
3 1
2 2
4 5
4 5
5 2
1 1
2 4
3 3
4 2
3 1
1 1
5 2
1 3
3 1
4 2
1 3
3 3
4 2
4 2
 6 20
4 6 1 3 2 5
2 2
6 5
3 4
3 4
5 6
3 3
5 5
6 6
4 3
2 2
2 2
5 2
3 4
1 4
5 2
4 3
2 5
1 4
3 1
4 3
 2 10
1 2
1 1
2 2
2 2
1 1
1 1
2 2
2 2
1 1
2 2
1 1
 5 3
5 2 3 4 1
2 4
1 4
3 4
 4 1
4 3 1 2
3 4
 3 1
1 3 2
1 2
 2 10
2 1
2 1
1 2
1 1
2 1
1 1
2 1
1 1
1 1
2 1
2 1
 3 1
2 3 1
1 1
 8 1
3 4 1 2 7 8 5 6
3 4
 3 10
1 2 3
2 2
1 1
2 2
3 3
1 1
3 3
3 3
3 3
2 2
1 1

3 2 1 
 6 2 5 7 3 1 4 
 4 2 3 1 
 9 8 6 7 5 3 4 2 1 
 7 6 5 4 3 2 1 
 3 2 1 
 8 4 7 2 6 5 3 1 
 2 3 1 
 4 12 7 1 16 19 3 10 14 8 13 2 11 9 20 5 18 17 6 15 
 6 8 9 4 5 1 7 2 3 
 5 4 3 2 1 
 3 4 1 2 
 5 3 2 4 1 6 
 62 3 52 12 61 36 65 54 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 34 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 83 42 13 44 72 22 64 57 25 19 9 10 70 18 68 32 16 20 80 23 79 24 63 4 51 59 41 74 48 40 33 46 1 55 56 78 
 1 
 3 5 1 4 2 
 4 6 3 1 5 2 
 1 2 
 5 4 3 2 1 
 4 3 2 1 
 3 1 2 
 2 1 
 2 3 1 
 3 4 2 1 7 8 5 6 
 1 2 3 

#include <bits/stdc++.h>
using namespace std;
string multiply(string num1, string num2) {
  int len1 = num1.size();
  int len2 = num2.size();
  if (len1 == 0 || len2 == 0) return "0";
  vector<int> result(len1 + len2, 0);
  int i_n1 = 0;
  int i_n2 = 0;
  for (int i = len1 - 1; i >= 0; i--) {
    int carry = 0;
    int n1 = num1[i] - '0';
    i_n2 = 0;
    for (int j = len2 - 1; j >= 0; j--) {
      int n2 = num2[j] - '0';
      int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
      carry = sum / 10;
      result[i_n1 + i_n2] = sum % 10;
      i_n2++;
    }
    if (carry > 0) result[i_n1 + i_n2] += carry;
    i_n1++;
  }
  int i = result.size() - 1;
  while (i >= 0 && result[i] == 0) i--;
  if (i == -1) return "0";
  string s = "";
  while (i >= 0) s += std::to_string(result[i--]);
  return s;
}
int isPrime(long long int n) {
  if (n <= 1) return 0;
  for (long long int i = 2; i < n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long int modFact(long long int n, long long int p) {
  if (n >= p) return 0;
  long long int result = 1;
  for (long long int i = 1; i <= n; i++) result = (result * i) % p;
  return result;
}
bool isSubSequence(string str1, string str2, int m, int n) {
  if (m == 0) return true;
  if (n == 0) return false;
  if (str1[m - 1] == str2[n - 1])
    return isSubSequence(str1, str2, m - 1, n - 1);
  return isSubSequence(str1, str2, m, n - 1);
}
long long int isSubstring(string s1, string s2) {
  long long int M = s1.length();
  long long int N = s2.length();
  for (long long int i = 0; i <= N - M; i++) {
    long long int j;
    for (j = 0; j < M; j++)
      if (s2[i + j] != s1[j]) break;
    if (j == M) return i;
  }
  return -1;
}
vector<long long int> v[1000001];
long long int vis[1000001];
long long int a[100001];
vector<long long int> temp;
vector<pair<long long int, long long int>> yu;
void dfs(long long int x) {
  vis[x] = 1;
  temp.push_back(x);
  for (long long int i = 0; i < v[x].size(); i++) {
    if (vis[v[x][i]] == 0) dfs(v[x][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, q;
  cin >> n >> q;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  map<pair<long long int, long long int>, long long int> m;
  for (long long int i = 0; i < q; i++) {
    long long int x, y;
    cin >> x >> y;
    if (x == y || m[make_pair(x, y)] > 0 || m[make_pair(y, x)] > 0) continue;
    v[x].push_back(y);
    v[y].push_back(x);
    m[make_pair(x, y)]++;
    m[make_pair(y, x)]++;
  }
  for (long long int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      temp.clear();
      yu.clear();
      dfs(i);
      for (long long int j = 0; j < temp.size(); j++) {
        yu.push_back(make_pair(a[temp[j]], temp[j]));
      }
      sort(yu.begin(), yu.end());
      for (long long int j = 0; j < yu.size() / 2; j++) {
        if (a[yu[yu.size() - 1 - j].first] > a[yu[j].first])
          swap(a[yu[j].second], a[yu[yu.size() - 1 - j].second]);
      }
    }
  }
  for (long long int i = 1; i <= n; i++) cout << a[i] << " ";
  return 0;
}
