#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 9, MOD = 1e7;
char ch[50][50];
int a[M];
int dp[101][101], cnt = 0, sum, c = 0, mx = MOD;
bool vis[101][100], vi[102];
int m, n;
vector<int> v[1001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    vis[x][y] = 1;
  }
  for (int i = 1; i <= n; i++) {
    sum = 0;
    if (v[i].size() >= 2) {
      for (int j = 0; j < v[i].size(); j++) {
        int d = v[i][j];
        for (int k = j + 1; k < v[i].size(); k++) {
          int c = v[i][k];
          if (vis[c][d] || vis[d][c]) {
            mx = min(mx, a[i] + a[d] + a[c]);
          }
        }
      }
    }
  }
  if (mx == MOD)
    puts("-1");
  else
    cout << mx << endl;
  return 0;
}
