#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<vector<unsigned long>> edge(N);
  for (unsigned long i{0}, u, v; i < M; ++i) {
    cin >> u >> v;
    edge[--u].push_back(--v);
    edge[v].push_back(u);
  }
  for (unsigned long i{0}; i < N; ++i)
    for (const auto& j : edge[i])
      if (D[i] == D[j]) return 0 & puts("-1");
  abort();
  return 0;
}
