#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 5;
const long long p = 1000000009;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long b[m];
  map<pair<long long, long long>, long long> mp;
  long long mini = INT_MAX;
  for (long long i = (0); i < (m); i++) {
    long long x, y;
    cin >> x >> y;
    mp[make_pair(x, y)]++;
    mp[make_pair(y, x)]++;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      for (long long k = 1; k <= n; k++) {
        if (mp[make_pair(i, j)] > 0 and mp[make_pair(j, k)] > 0 and
            mp[make_pair(k, i)] > 0 and i != j and j != k and k != i) {
          mini = min(mini, a[i] + a[j] + a[k]);
        }
      }
    }
  }
  if (mini == INT_MAX)
    cout << "-1\n";
  else
    cout << mini;
}
int32_t main() { solve(); }
