#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
using namespace std;
const double EPS = 1e-9;
const long long INF = 10e17;
std::istream &operator>>(std::istream &in, set<long long> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> ds(n);
  for (int i = 0; i < (n); ++i) cin >> ds[i];
  vector<vector<int>> edges(n);
  for (int _ = 0; _ < (m); ++_) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 0; i < (n); ++i) {
    bool ok = [&] {
      for (int j : edges[i]) {
        if (ds[i] >= ds[j]) return true;
      }
      return false;
    }();
    if (!ok) {
      cout << -1 << endl;
      return 0;
      ;
    }
  }
}
