#include <bits/stdc++.h>
using namespace std;
template <typename T>
void fin(T a) {
  cout << a << endl;
  exit(0);
}
signed main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > d(n);
  vector<int> dd(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    d[i] = pair<int, int>(a, i);
    dd[i] = a;
  }
  sort(d.begin(), d.end());
  if (d[0] != d[1]) fin(-1);
  std::vector<pair<int, int> > edge[n];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge[u].push_back(pair<int, int>(v, i));
    edge[v].push_back(pair<int, int>(u, i));
  }
  for (int i = 0; i < n; i++) {
    bool out = true;
    for (auto p : edge[i]) {
      if (d[p.first] <= d[i]) out = false;
    }
    if (out) fin(-1);
  }
  assert(false);
}
