#include <bits/stdc++.h>
using namespace std;
int n, m, p[105], ans = ((int)(1e9));
bool b[105][105];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    b[x][y] = b[y][x] = 1;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k) {
        if (i == j || j == k || k == i) continue;
        if (b[i][j] && b[j][k] && b[k][i]) ans = min(ans, p[i] + p[j] + p[k]);
      }
  if (ans == ((int)(1e9)))
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
