#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
template <typename T1, typename T2>
inline void chmin(T1 &a, const T2 &b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, const T2 &b) {
  if (a < b) a = b;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<lint> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  set<int> st;
  bool ok = false;
  for (int u = 0; u < n; u++) {
    for (auto v : g[u]) {
      if (d[u] == d[v]) ok = true;
    }
  }
  if (ok)
    assert(false);
  else
    cout << -1 << endl;
  return 0;
}
