#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 200005, inf = 1000000000;
template <class T>
void read(T &x) {
  int sgn = 1;
  char ch;
  x = 0;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') ch = getchar(), sgn = -1;
  for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  x *= sgn;
}
template <class T>
void write(T x) {
  if (x < 0)
    putchar('-'), write(-x);
  else if (x < 10)
    putchar(x + '0');
  else
    write(x / 10), putchar(x % 10 + '0');
}
int n, m, fa[N], val[N], d[N], e[M];
vector<pair<int, int> > g[M];
bool flag = true;
int findroot(int u) {
  if (fa[u] == u) return u;
  int r = findroot(fa[u]);
  val[u] ^= val[fa[u]];
  return fa[u] = r;
}
bool merge(int u, int v) {
  int ru = findroot(u), rv = findroot(v);
  if (ru == rv) return false;
  fa[ru] = rv, val[ru] = val[u] ^ val[v] ^ 1;
  return true;
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++) read(d[i]);
  for (int i = 1; i <= m; i++) {
    int u, v;
    read(u), read(v), e[i] = inf;
    g[u].push_back(make_pair(i, v));
    g[v].push_back(make_pair(i, u));
  }
  for (int i = 1; i <= n; i++) fa[i] = i, val[i] = 0;
  for (int i = 1; i <= n; i++) {
    bool tmp = false;
    pair<int, int> pos;
    for (int j = 0; j < g[i].size(); j++) {
      if (d[g[i][j].second] <= d[i]) tmp = true;
      if (d[g[i][j].second] < d[i]) pos = g[i][j];
    }
    if (!tmp) flag = false;
    if (pos.first) {
      if (merge(i, pos.second)) e[pos.first] = d[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (d[g[i][j].second] == d[i]) {
        if (merge(i, g[i][j].second)) e[g[i][j].first] = d[i];
      }
    }
  }
  if (flag) {
  } else
    puts("-1");
  return 0;
}
