#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const long double eps = 1e-11;
int diri[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int dirk[] = {1, 0, -1, 0, 1, -1, 1, -1, 0};
int n, m, a, b;
map<int, vector<int> > mp;
int mat[1001][1001];
vector<int> price;
int main() {
  cin >> n >> m;
  mp.clear();
  memset(mat, 0, sizeof mat);
  price = vector<int>(n);
  for (int i = ((int)0); i <= ((int)n - 1); i++) cin >> price[i];
  for (int i = ((int)0); i <= ((int)m - 1); i++) {
    cin >> a >> b;
    a--, b--;
    mp[a].push_back(b);
    mp[b].push_back(a);
    mat[a][b] = mat[b][a] = 1;
  }
  int ans = oo;
  for (int i = ((int)0); i <= ((int)n - 1); i++) {
    vector<int> me = mp[i];
    for (int k = ((int)0); k <= ((int)me.size() - 1); k++) {
      for (int j = ((int)k + 1); j <= ((int)me.size() - 1); j++) {
        int d = me[k], e = me[j];
        if (mat[d][e] and i != d and i != e and d != e) {
          ans = min(ans, price[i] + price[d] + price[e]);
        }
      }
    }
  }
  if (ans < oo)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
