#include <bits/stdc++.h>
using namespace std;
bool a[101][101];
int mins = 1000000000, d[101];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> d[i];
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u][v] = a[v][u] = 1;
  }
  for (int i = 1; i <= n - 2; i++)
    for (int j = i + 1; j <= n - 1; j++)
      for (int k = j + 1; k <= n; k++) {
        if (a[i][j] && a[j][k] && a[i][k]) mins = min(mins, d[i] + d[j] + d[k]);
      }
  cout << (mins == 1000000000 ? -1 : mins);
  return 0;
}
