#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, a[105], minn = 9999999, map[105][105], x, y, ans;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(map, 0, sizeof(map));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    map[x][y] = map[y][x] = 1;
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (map[i][k] && map[k][j] && map[i][j]) {
          ans = a[i] + a[j] + a[k];
          if (ans < minn) minn = ans;
        }
  if (minn == 9999999)
    printf("-1\n");
  else
    printf("%d\n", minn);
  return 0;
}
