#include <bits/stdc++.h>
using namespace std;
int cost[105], w[105][105];
int main() {
  int n, m, u, v;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", cost + i);
    }
    memset(w, 0, sizeof(w));
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &u, &v);
      u--;
      v--;
      w[u][v] = w[v][u] = 1;
    }
    int ans = 1 << 30;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          if (w[i][j] && w[j][k] && w[k][i]) {
            ans = min(ans, cost[i] + cost[j] + cost[k]);
          }
        }
      }
    }
    if (ans == 1 << 30) {
      printf("-1\n");
    } else {
      printf("%d\n", ans);
    }
  }
  return 0;
}
