#include <bits/stdc++.h>
using namespace std;
int N, M;
int v[1005];
int a[1005][1005];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x][y] = a[y][x] = 1;
  }
  int ans = (1 << 30);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      for (int k = 1; k <= N; k++)
        if (a[i][j] == 1 && a[i][k] == 1 && a[j][k] == 1)
          ans = min(ans, v[i] + v[j] + v[k]);
  if (ans == (1 << 30)) ans = -1;
  printf("%d\n", ans);
  return 0;
}
