#include <bits/stdc++.h>
using namespace std;
int dirx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int diry[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int a[1000];
int A[1000][1000] = {0};
int main() {
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    A[u][v] = 1;
    A[v][u] = 1;
  }
  int ans = 1 << 29;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int l = 0; l < n; l++) {
        if (A[i][j] && A[i][l] && A[j][l]) ans = min(ans, a[i] + a[j] + a[l]);
      }
    }
  }
  if (ans == (1 << 29)) ans = -1;
  cout << ans;
  return 0;
}
