#include <bits/stdc++.h>
using namespace std;
namespace DinicFlows {
const int Inf = 0x3f3f3f3f;
const int MN = 1015, MM = 2005;
int N, S, T;
int h[MN], iter[MN], nxt[MM * 2], to[MM * 2], w[MM * 2], tot;
inline void SetST(int _S, int _T) { S = _S, T = _T; }
inline void Init(int _N) {
  N = _N, tot = 1;
  for (int i = 1; i <= N; ++i) h[i] = 0;
  SetST(_N - 1, _N);
}
inline void ins(int u, int v, int x) {
  if (tot + 1 >= MM * 2) {
    puts("Error : too many edges.");
    return;
  }
  nxt[++tot] = h[u], to[tot] = v, w[tot] = x, h[u] = tot;
}
inline void insw(int u, int v, int w1 = Inf, int w2 = 0) {
  if (!u) u = S;
  if (!v) v = T;
  ins(u, v, w1), ins(v, u, w2);
}
int lv[MN], que[MN], l, r;
inline bool Lvl() {
  for (int i = 1; i <= N; ++i) lv[i] = 0;
  lv[S] = 1;
  que[l = r = 1] = S;
  while (l <= r) {
    int u = que[l++];
    for (int i = h[u]; i; i = nxt[i])
      if (w[i] && !lv[to[i]]) {
        lv[to[i]] = lv[u] + 1;
        que[++r] = to[i];
      }
  }
  return lv[T] != 0;
}
int Flow(int u, int f) {
  if (u == T) return f;
  int d = 0, s = 0;
  for (int &i = iter[u]; i; i = nxt[i])
    if (w[i] && lv[to[i]] == lv[u] + 1) {
      d = Flow(to[i], std::min(f, w[i]));
      f -= d, s += d;
      w[i] -= d, w[i ^ 1] += d;
      if (!f) break;
    }
  return s;
}
inline int Dinic() {
  int Ans = 0;
  while (Lvl()) {
    for (int i = 1; i <= N; ++i) iter[i] = h[i];
    Ans += Flow(S, Inf);
  }
  return Ans;
}
}  // namespace DinicFlows
int n, m, k;
int a[1005], s[1005], b[1005];
int eu[1005], ev[1005];
std::vector<int> G[1005];
void TaskSolve();
int main() {
  int tests = 1;
  while (tests--) {
    TaskSolve();
  }
  return 0;
}
int id[1005], iid[1005], tmp[1005];
void Solve(int lb, int rb, int l, int r) {
  if (l > r) return;
  if (lb == rb) {
    for (int i = l; i <= (r); ++i) b[id[i]] = s[lb];
    return;
  }
  int mid = (lb + rb) >> 1;
  int len = r - l + 1;
  int lp = l, rp = r;
  {
    DinicFlows::Init(len + 2);
    for (int i = l; i <= (r); ++i)
      for (int &v : G[id[i]])
        if (l <= iid[v] && iid[v] <= r)
          DinicFlows::insw(i - l + 1, iid[v] - l + 1);
    for (int i = l; i <= (r); ++i) {
      if (a[id[i]] <= s[mid])
        DinicFlows::insw(0, i - l + 1, 1);
      else
        DinicFlows::insw(i - l + 1, 0, 1);
    }
    DinicFlows::Dinic();
  }
  for (int i = l; i <= (r); ++i)
    if (DinicFlows::lv[i - l + 1])
      tmp[lp++] = id[i];
    else
      tmp[rp--] = id[i];
  for (int i = l; i <= (r); ++i) iid[id[i] = tmp[i]] = i;
  Solve(lb, mid, l, rp);
  Solve(mid + 1, rb, lp, r);
}
void TaskSolve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i), s[i] = a[i];
  sort(s + 1, s + n + 1);
  k = unique(s + 1, s + n + 1) - s - 1;
  for (int i = 1; i <= (m); ++i) {
    scanf("%d%d", &eu[i], &ev[i]);
    G[ev[i]].push_back(eu[i]);
  }
  for (int i = 1; i <= (n); ++i) iid[id[i] = i] = i;
  Solve(1, k, 1, n);
  for (int i = 1; i <= (n); ++i) printf("%d%c", b[i], " \n"[i == n]);
}

### Prompt

In cpp, your task is to solve the following problem:

There are n reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingly, the "Top Reindeer" title is just a measure of upvotes and has nothing to do with their skill level in the reindeer games, but they still give it the utmost importance.

Currently, the i-th reindeer has a score of a_i. You would like to influence the leaderboard with some operations. In an operation, you can choose a reindeer, and either increase or decrease his score by 1 unit. Negative scores are allowed.

You have m requirements for the resulting scores. Each requirement is given by an ordered pair (u, v), meaning that after all operations, the score of reindeer u must be less than or equal to the score of reindeer v.

Your task is to perform the minimum number of operations so that all requirements will be satisfied.

Input

The first line contains two integers n and m (2≤ n≤ 1000; 1≤ m≤ 1000) — the number of reindeer and requirements, respectively.

The second line contains n integers a_1,…, a_n (1≤ a_i≤ 10^9), where a_i is the current score of reindeer i.

The next m lines describe the requirements.

The i-th of these lines contains two integers u_i and v_i (1≤ u_i, v_i≤ n; u_i≠ v_i) — the two reindeer of the i-th requirement.

Output

Print n integers b_1,…, b_n (-10^{15}≤ b_i≤ 10^{15}), where b_i is the score of the i-th reindeer after all operations.

If there are multiple solutions achieving the minimum number of operations, you may output any.

We can prove that there is always an optimal solution such that |b_i|≤ 10^{15} for all i.

Examples

Input


7 6
3 1 4 9 2 5 6
1 2
2 3
3 4
4 5
5 6
6 7


Output


1 1 4 4 4 5 6 


Input


4 6
6 5 8 2
3 1
4 1
3 2
1 2
2 3
3 1


Output


6 6 6 2 


Input


10 18
214 204 195 182 180 176 176 172 169 167
1 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
10 2
6 1
6 2
6 3
6 4
6 5
6 7
6 8
6 9
6 10


Output


204 204 195 182 180 167 176 172 169 167 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace DinicFlows {
const int Inf = 0x3f3f3f3f;
const int MN = 1015, MM = 2005;
int N, S, T;
int h[MN], iter[MN], nxt[MM * 2], to[MM * 2], w[MM * 2], tot;
inline void SetST(int _S, int _T) { S = _S, T = _T; }
inline void Init(int _N) {
  N = _N, tot = 1;
  for (int i = 1; i <= N; ++i) h[i] = 0;
  SetST(_N - 1, _N);
}
inline void ins(int u, int v, int x) {
  if (tot + 1 >= MM * 2) {
    puts("Error : too many edges.");
    return;
  }
  nxt[++tot] = h[u], to[tot] = v, w[tot] = x, h[u] = tot;
}
inline void insw(int u, int v, int w1 = Inf, int w2 = 0) {
  if (!u) u = S;
  if (!v) v = T;
  ins(u, v, w1), ins(v, u, w2);
}
int lv[MN], que[MN], l, r;
inline bool Lvl() {
  for (int i = 1; i <= N; ++i) lv[i] = 0;
  lv[S] = 1;
  que[l = r = 1] = S;
  while (l <= r) {
    int u = que[l++];
    for (int i = h[u]; i; i = nxt[i])
      if (w[i] && !lv[to[i]]) {
        lv[to[i]] = lv[u] + 1;
        que[++r] = to[i];
      }
  }
  return lv[T] != 0;
}
int Flow(int u, int f) {
  if (u == T) return f;
  int d = 0, s = 0;
  for (int &i = iter[u]; i; i = nxt[i])
    if (w[i] && lv[to[i]] == lv[u] + 1) {
      d = Flow(to[i], std::min(f, w[i]));
      f -= d, s += d;
      w[i] -= d, w[i ^ 1] += d;
      if (!f) break;
    }
  return s;
}
inline int Dinic() {
  int Ans = 0;
  while (Lvl()) {
    for (int i = 1; i <= N; ++i) iter[i] = h[i];
    Ans += Flow(S, Inf);
  }
  return Ans;
}
}  // namespace DinicFlows
int n, m, k;
int a[1005], s[1005], b[1005];
int eu[1005], ev[1005];
std::vector<int> G[1005];
void TaskSolve();
int main() {
  int tests = 1;
  while (tests--) {
    TaskSolve();
  }
  return 0;
}
int id[1005], iid[1005], tmp[1005];
void Solve(int lb, int rb, int l, int r) {
  if (l > r) return;
  if (lb == rb) {
    for (int i = l; i <= (r); ++i) b[id[i]] = s[lb];
    return;
  }
  int mid = (lb + rb) >> 1;
  int len = r - l + 1;
  int lp = l, rp = r;
  {
    DinicFlows::Init(len + 2);
    for (int i = l; i <= (r); ++i)
      for (int &v : G[id[i]])
        if (l <= iid[v] && iid[v] <= r)
          DinicFlows::insw(i - l + 1, iid[v] - l + 1);
    for (int i = l; i <= (r); ++i) {
      if (a[id[i]] <= s[mid])
        DinicFlows::insw(0, i - l + 1, 1);
      else
        DinicFlows::insw(i - l + 1, 0, 1);
    }
    DinicFlows::Dinic();
  }
  for (int i = l; i <= (r); ++i)
    if (DinicFlows::lv[i - l + 1])
      tmp[lp++] = id[i];
    else
      tmp[rp--] = id[i];
  for (int i = l; i <= (r); ++i) iid[id[i] = tmp[i]] = i;
  Solve(lb, mid, l, rp);
  Solve(mid + 1, rb, lp, r);
}
void TaskSolve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i), s[i] = a[i];
  sort(s + 1, s + n + 1);
  k = unique(s + 1, s + n + 1) - s - 1;
  for (int i = 1; i <= (m); ++i) {
    scanf("%d%d", &eu[i], &ev[i]);
    G[ev[i]].push_back(eu[i]);
  }
  for (int i = 1; i <= (n); ++i) iid[id[i] = i] = i;
  Solve(1, k, 1, n);
  for (int i = 1; i <= (n); ++i) printf("%d%c", b[i], " \n"[i == n]);
}

```