#include <bits/stdc++.h>
using namespace std;
ifstream in("in.txt");
int main() {
  int n, m;
  int a[1001] = {0}, u[10000], v[10000];
  int i, j, k, r, cmin = 100000000;
  cin >> n >> m;
  bool f = 0;
  for (i = 1; i < n + 1; i++) cin >> a[i];
  for (i = 0; i < m; i++) {
    cin >> u[i];
    cin >> v[i];
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (u[i] == v[j]) {
        for (k = 0; k < m; k++) {
          if (v[i] == u[k] && v[k] == u[j]) {
            f = 1;
            r = a[u[i]] + a[v[i]] + a[v[k]];
            if (cmin > r) cmin = r;
          }
          if (v[i] == v[k] && u[j] == u[k]) {
            f = 1;
            r = a[v[i]] + a[v[j]] + a[u[k]];
            if (cmin > r) cmin = r;
          }
        }
      }
    }
  }
  if (f)
    cout << cmin;
  else
    cout << "-1";
  return 0;
}
