#include <bits/stdc++.h>
using namespace std;
long long d[100010];
vector<int> G[100010];
int main() {
  int i, j, n, m;
  cin >> n >> m;
  long long mn = 100000000000000;
  for (i = 0; i < n; i++) {
    cin >> d[i];
    mn = min(mn, d[i]);
  }
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << -1 << endl;
  return 0;
  for (i = 0; i < n; i++) {
    if (d[i] != mn) continue;
    long long x = 1000000000000;
    for (j = 0; j < G[i].size(); j++) {
      x = min(x, d[G[i][j]]);
    }
    if (x != mn) {
      cout << -1 << endl;
      return 0;
    }
  }
}
