#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n, m;
vector<vector<pair<int, int> > > g;
vector<int> a, b;
void dfs(int v, int pre, int t = 0) {
  b[v] = t;
  for (auto p : g[v]) {
    int u = p.first;
    if (u != pre) dfs(u, v, 1 - t);
  }
}
int main() {
  cin >> n >> m;
  g = vector<vector<pair<int, int> > >(n);
  a = vector<int>(n);
  b = vector<int>(n, -1);
  for (auto &i : a) cin >> i;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  bool B = 0;
  for (int i = 0; i < n; i++) {
    bool flag = 1;
    for (auto p : g[i]) {
      int v = p.first;
      if (a[v] <= a[i]) flag = 0;
    }
    B |= flag;
  }
  B = 1;
  if (B) {
    cout << -1 << endl;
    return 0;
  }
}
