#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int MAX = 1000;
const int inf = 999999999;
const int p1 = 104393321, p2 = 104393329;
int a[MAX], adj[MAX][MAX], ans = inf;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < int(n); ++i) cin >> a[i];
  for (int i = (0); i < int(m); ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x][y] = 1;
    adj[y][x] = 1;
  }
  for (int i = (0); i < int(n); ++i) {
    for (int j = (i + 1); j < int(n); ++j) {
      for (int t = (j + 1); t < int(n); ++t) {
        if (adj[i][j] && adj[j][t] && adj[i][t])
          ans = min(ans, a[i] + a[t] + a[j]);
      }
    }
  }
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
