#include <bits/stdc++.h>
using namespace std;
bool vis[100005];
long long parent[100005];
vector<long long> vv;
vector<long long> v[100005];
map<pair<long long, long long>, long long> mp;
long long a[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1, tmp;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> l;
    a[i] = l;
  }
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    v[j].push_back(k);
    v[k].push_back(j);
    mp[{j, k}] = 1;
  }
  min1 = 1e15;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < v[i].size(); j++) {
      l = v[i][j];
      for (k = 0; k < v[l].size(); k++) {
        sum = v[l][k];
        for (long long ii = 0; ii < v[sum].size(); ii++) {
          sum1 = v[sum][ii];
          if (sum1 == i) {
            long long d = a[i] + a[l] + a[sum];
            min1 = min(min1, d);
          }
        }
      }
    }
  }
  if (min1 == 1e15) {
    cout << -1 << endl;
  } else {
    cout << min1 << endl;
  }
}
