#include <bits/stdc++.h>
using namespace std;
int a[1000];
bool b[1000][1000];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%d", &a[i]);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    b[x][y] = true;
    b[y][x] = true;
  }
  int mincost = 1000000000;
  for (int x = 0; x < N; x++)
    for (int y = 0; y < N; y++)
      for (int z = 0; z < N; z++)
        if (b[x][y] && b[y][z] && b[x][z])
          if (a[x] + a[y] + a[z] < mincost) mincost = a[x] + a[y] + a[z];
  if (mincost == 1000000000)
    printf("-1");
  else
    printf("%d\n", mincost);
  return 0;
}
