#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long OO = (long long)1e18;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long fast_power(double base, long long power) {
  if (power == 1) return base;
  if (power % 2 == 0)
    return fast_power((base * base), power / 2);
  else
    return (base * fast_power((base * base), power / 2));
}
void Qalbaz() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
}
int main() {
  Qalbaz();
  int n, m;
  cin >> n >> m;
  map<pair<int, int>, bool> mp;
  int u, v;
  vector<int> vec(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    mp[make_pair(u, v)] = true;
  }
  int c = 0;
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    c = 0;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (mp[make_pair(i, j)] || mp[make_pair(j, i)]) {
        c++;
        for (int k = 1; k <= n; k++) {
          if (i == k || k == j) continue;
          if (mp[make_pair(i, k)] || mp[make_pair(k, i)]) c++;
          if (mp[make_pair(j, k)] || mp[make_pair(k, j)]) c++;
          if (c == 3) ans = min(ans, vec[i] + vec[j] + vec[k]);
          c = 1;
        }
      }
      c = 0;
    }
  }
  if (ans < 1e9)
    cout << ans;
  else
    cout << -1;
  return 0;
}
