#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  if (n < 3 || m < 3) {
    cout << -1 << "\n";
    return;
  }
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  set<pair<int, int>> st;
  for (int i = 0; i < m; ++i) {
    int first, second;
    cin >> first >> second;
    first--, second--;
    if (first > second) {
      swap(first, second);
    }
    st.insert({first, second});
  };
  int ans = (1 << 30);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = k + 1; k < n; ++k) {
        if (st.count({i, j}) && st.count({j, k}) && st.count({i, k})) {
          ans = min(ans, a[i] + a[j] + a[k]);
        }
      }
    }
  }
  cout << (ans == (1 << 30) ? -1 : ans) << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
