#include <bits/stdc++.h>
bool map[110][110], match;
int num[110], min, m, n;
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &num[i]);
    for (int j = 0; j < m; ++j) map[i][j] = false;
  }
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    map[a - 1][b - 1] = map[b - 1][a - 1] = true;
  }
  min = 1000000000;
  match = false;
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < m; ++j)
      if (map[i][j])
        for (int k = 0; k < m; ++k)
          if (map[j][k] && k != i) {
            if (map[k][i]) {
              match = true;
              if (num[i] + num[j] + num[k] < min)
                min = num[i] + num[j] + num[k];
            }
          }
  if (match)
    printf("%d\n", min);
  else
    printf("-1\n");
  return 0;
}
