#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<int, int> > v;
  vector<int> result;
  int n, pir;
  cin >> n >> pir;
  int price[n];
  for (int i = 0; i < n; i++) {
    cin >> price[i];
  }
  for (int i = 0; i < pir; i++) {
    pair<int, int> p;
    cin >> p.first;
    cin >> p.second;
    v.push_back(p);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      for (int k = j + 1; k <= n; k++) {
        if ((find(v.begin(), v.end(), make_pair(i, j)) != v.end() ||
             find(v.begin(), v.end(), make_pair(j, i)) != v.end()) &&
            (find(v.begin(), v.end(), make_pair(j, k)) != v.end() ||
             find(v.begin(), v.end(), make_pair(k, j)) != v.end()) &&
            (find(v.begin(), v.end(), make_pair(i, k)) != v.end() ||
             find(v.begin(), v.end(), make_pair(k, i)) != v.end())) {
          int x = price[i - 1] + price[j - 1] + price[k - 1];
          result.push_back(x);
        }
      }
    }
  }
  sort(result.begin(), result.end());
  if (result.size() == 0) {
    cout << -1 << endl;
  } else {
    cout << result[0] << endl;
  }
  return 0;
}
