#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const long long mod = 1e7;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, c = oo;
  cin >> n >> m;
  vector<int> a(n + 1);
  map<int, set<int>> b;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    b[x].insert(y), b[y].insert(x);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      for (int k = j + 1; k <= n; ++k) {
        if (b[i].count(j) && b[i].count(k) && b[j].count(k))
          c = min(c, a[i] + a[j] + a[k]);
      }
  cout << (c == oo ? -1 : c);
  return 0;
}
