#include <bits/stdc++.h>
int main() {
  using namespace std;
  unsigned long N, M;
  cin >> N >> M;
  vector<unsigned long> D(N);
  for (auto& i : D) cin >> i;
  vector<unsigned long> edges(M);
  vector<vector<unsigned long>> edge(N);
  for (unsigned long i{0}, u, v; i < M; ++i) {
    cin >> u >> v;
    edge[--u].push_back(i);
    edge[--v].push_back(i);
    edges[i] = u ^ v;
  }
  [&] {
    for (unsigned long i{0}; i < N; ++i)
      if ([&] {
            for (auto j : edge[i])
              if (D[i] >= D[edges[j] ^ i]) return false;
            return true;
          }())
        return;
    puts("-1");
    exit(0);
  }();
  abort();
  return 0;
}
