#include <bits/stdc++.h>
using namespace std;
int v[1002], head[1002], seq[30], cnt = 0, used[30], Min = 1234567890;
typedef struct nodel {
  int v, next;
} node;
node edge[10002];
void dfs(int u, int cur, int flag) {
  int p = 0, v1 = 0;
  if (cur == 3) return;
  for (p = head[u]; p != -1; p = edge[p].next) {
    v1 = edge[p].v;
    seq[cur] = u;
    if (cur == 2 && v1 == seq[0]) {
      int a = seq[0], b = seq[1], c = seq[2];
      Min = Min < v[a] + v[b] + v[c] ? Min : v[a] + v[b] + v[c];
      return;
    } else if (!used[v1]) {
      used[u] = 1;
      dfs(v1, cur + 1, flag);
      used[u] = 0;
    }
  }
  return;
}
void add_edge(int u, int v) {
  edge[cnt].v = v;
  edge[cnt].next = head[u];
  head[u] = cnt++;
  edge[cnt].v = u;
  edge[cnt].next = head[v];
  head[v] = cnt++;
}
int main() {
  int i = 0, n = 0, m = 0, ans = 1234567890;
  memset(head, -1, sizeof(head));
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &v[i]);
  while (m--) {
    int a = 0, b = 0;
    scanf("%d %d", &a, &b);
    add_edge(a, b);
  }
  for (i = 1; i <= n; i++) {
    dfs(i, 0, i);
    if (ans > Min && Min != 1234567890) ans = Min;
  }
  if (ans == 1234567890)
    cout << "-1" << endl;
  else
    printf("%d\n", ans);
  return 0;
}
