#include <bits/stdc++.h>
using namespace std;
int matriz[104][104];
int n, m, a, b;
int p[104];
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    matriz[a][b] = 1;
    matriz[b][a] = 1;
  }
  int menor = 1 << 30;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (matriz[i][j] && matriz[i][k] && matriz[j][k]) {
          int tot = p[i] + p[j] + p[k];
          if (tot < menor) menor = tot;
        }
      }
    }
  }
  if (menor != 1 << 30)
    printf("%d\n", menor);
  else
    printf("-1\n");
}
