#include <bits/stdc++.h>
int main() {
  int n, m, i, j, k, cost[100], ans = 0x7fffffff;
  static char mat[100][100];
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", cost + i);
  while (m--) {
    scanf("%d%d", &i, &j);
    i--;
    j--;
    mat[i][j] = mat[j][i] = 1;
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (!mat[i][j]) continue;
      for (k = j + 1; k < n; k++)
        if (mat[j][k] && mat[k][i] && cost[i] + cost[j] + cost[k] < ans)
          ans = cost[i] + cost[j] + cost[k];
    }
  }
  if (ans == 0x7fffffff) ans = -1;
  printf("%d\n", ans);
  return 0;
}
