#include <bits/stdc++.h>
template <class T>
inline T read() {
  T r = 0, f = 0;
  char c;
  while (!isdigit(c = getchar())) f |= (c == '-');
  while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar();
  return f ? -r : r;
}
template <class T>
inline T min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
namespace MF {
struct E {
  int v, c, nxt;
  E() {}
  E(int v, int c, int nxt) : v(v), c(c), nxt(nxt) {}
} e[10101 << 1];
int n, s, t, s_e, head[1111], cur[1111], lev[1111];
int hd, tl, q[1111];
inline void a_e(int u, int v, int c) {
  e[++s_e] = E(v, c, head[u]);
  head[u] = s_e;
}
inline void add(int u, int v, int c) { a_e(u, v, c), a_e(v, u, 0); }
inline void init(int N, int S, int T) {
  s_e = 1, n = N, s = S, t = T;
  for (int i = 1; i <= n; i++) head[i] = 0;
}
inline bool BFS() {
  for (int i = 1; i <= n; i++) lev[i] = 0, cur[i] = head[i];
  hd = tl = 0;
  q[++tl] = s, lev[s] = 1;
  while (hd ^ tl) {
    int u = q[++hd];
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (!e[i].c || lev[v]) continue;
      lev[v] = lev[u] + 1;
      if (v == t) return true;
      q[++tl] = v;
    }
  }
  return false;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int d = 0, used = 0;
  for (int &i = cur[u]; i; i = e[i].nxt) {
    int v = e[i].v, c = e[i].c;
    if (!c || lev[v] != lev[u] + 1) continue;
    d = dfs(v, min(f - used, c));
    if (!d) continue;
    e[i].c -= d;
    e[i ^ 1].c += d, used += d;
    if (used == f) break;
  }
  if (!used) lev[u] = 0;
  return used;
}
inline int solve() {
  int d = 0, flow = 0;
  while (BFS())
    while ((d = dfs(s, 1000000000))) flow += d;
  return flow;
}
}  // namespace MF
struct E {
  int v, nxt;
  E() {}
  E(int v, int nxt) : v(v), nxt(nxt) {}
} e[1111];
int n, m, s_e, head[1111];
int a[1111], ans[1111];
inline void a_e(int u, int v) {
  e[++s_e] = E(v, head[u]);
  head[u] = s_e;
}
int tim, vis[1111], num[1111], pos[1111];
inline std::vector<int> calc(int mid, std::vector<int> d) {
  tim++;
  int N = 0;
  for (auto i : d) {
    vis[i] = tim;
    num[i] = ++N;
    pos[N] = i;
  }
  int s = N + 1, t = N + 2;
  MF::init(t, s, t);
  for (auto u : d) {
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (vis[v] ^ tim) continue;
      MF::add(num[v], num[u], 1000000000);
    }
    if (a[u] > mid)
      MF::add(s, num[u], 1);
    else
      MF::add(num[u], t, 1);
  }
  MF::solve(), d.clear();
  for (int i = 1; i <= N; i++)
    if (MF::lev[i]) d.push_back(pos[i]);
  return d;
}
void solve(int l, int r, std::vector<int> d) {
  if (!d.size()) return;
  if (l == r) {
    for (auto i : d) ans[i] = l;
    return;
  }
  int mid = (l + r) >> 1;
  std::vector<int> A, B = calc(mid, d);
  for (auto i : B) vis[i] = 0;
  for (auto i : d)
    if (vis[i]) A.push_back(i);
  solve(l, mid, A), solve(mid + 1, r, B);
}
std::vector<int> d;
int main() {
  n = read<int>();
  m = read<int>();
  int l = 1e9, r = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = read<int>();
    d.push_back(i);
    l = min(l, a[i]);
    r = max(r, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    int u = read<int>();
    int v = read<int>();
    a_e(v, u);
  }
  solve(l, r, d);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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>
template <class T>
inline T read() {
  T r = 0, f = 0;
  char c;
  while (!isdigit(c = getchar())) f |= (c == '-');
  while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar();
  return f ? -r : r;
}
template <class T>
inline T min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
namespace MF {
struct E {
  int v, c, nxt;
  E() {}
  E(int v, int c, int nxt) : v(v), c(c), nxt(nxt) {}
} e[10101 << 1];
int n, s, t, s_e, head[1111], cur[1111], lev[1111];
int hd, tl, q[1111];
inline void a_e(int u, int v, int c) {
  e[++s_e] = E(v, c, head[u]);
  head[u] = s_e;
}
inline void add(int u, int v, int c) { a_e(u, v, c), a_e(v, u, 0); }
inline void init(int N, int S, int T) {
  s_e = 1, n = N, s = S, t = T;
  for (int i = 1; i <= n; i++) head[i] = 0;
}
inline bool BFS() {
  for (int i = 1; i <= n; i++) lev[i] = 0, cur[i] = head[i];
  hd = tl = 0;
  q[++tl] = s, lev[s] = 1;
  while (hd ^ tl) {
    int u = q[++hd];
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (!e[i].c || lev[v]) continue;
      lev[v] = lev[u] + 1;
      if (v == t) return true;
      q[++tl] = v;
    }
  }
  return false;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int d = 0, used = 0;
  for (int &i = cur[u]; i; i = e[i].nxt) {
    int v = e[i].v, c = e[i].c;
    if (!c || lev[v] != lev[u] + 1) continue;
    d = dfs(v, min(f - used, c));
    if (!d) continue;
    e[i].c -= d;
    e[i ^ 1].c += d, used += d;
    if (used == f) break;
  }
  if (!used) lev[u] = 0;
  return used;
}
inline int solve() {
  int d = 0, flow = 0;
  while (BFS())
    while ((d = dfs(s, 1000000000))) flow += d;
  return flow;
}
}  // namespace MF
struct E {
  int v, nxt;
  E() {}
  E(int v, int nxt) : v(v), nxt(nxt) {}
} e[1111];
int n, m, s_e, head[1111];
int a[1111], ans[1111];
inline void a_e(int u, int v) {
  e[++s_e] = E(v, head[u]);
  head[u] = s_e;
}
int tim, vis[1111], num[1111], pos[1111];
inline std::vector<int> calc(int mid, std::vector<int> d) {
  tim++;
  int N = 0;
  for (auto i : d) {
    vis[i] = tim;
    num[i] = ++N;
    pos[N] = i;
  }
  int s = N + 1, t = N + 2;
  MF::init(t, s, t);
  for (auto u : d) {
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (vis[v] ^ tim) continue;
      MF::add(num[v], num[u], 1000000000);
    }
    if (a[u] > mid)
      MF::add(s, num[u], 1);
    else
      MF::add(num[u], t, 1);
  }
  MF::solve(), d.clear();
  for (int i = 1; i <= N; i++)
    if (MF::lev[i]) d.push_back(pos[i]);
  return d;
}
void solve(int l, int r, std::vector<int> d) {
  if (!d.size()) return;
  if (l == r) {
    for (auto i : d) ans[i] = l;
    return;
  }
  int mid = (l + r) >> 1;
  std::vector<int> A, B = calc(mid, d);
  for (auto i : B) vis[i] = 0;
  for (auto i : d)
    if (vis[i]) A.push_back(i);
  solve(l, mid, A), solve(mid + 1, r, B);
}
std::vector<int> d;
int main() {
  n = read<int>();
  m = read<int>();
  int l = 1e9, r = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = read<int>();
    d.push_back(i);
    l = min(l, a[i]);
    r = max(r, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    int u = read<int>();
    int v = read<int>();
    a_e(v, u);
  }
  solve(l, r, d);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}

```