#include <bits/stdc++.h>
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
double nextDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long nextLong() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
char nextChar() {
  char x;
  scanf("%c", &x);
  return x;
}
void newLine() { printf("\n"); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long pow(long long a, long long b, long long MOD) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > MOD) x %= MOD;
    }
    y = (y * y);
    if (y > MOD) y %= MOD;
    b /= 2;
  }
  return x;
}
int countSetBit(long long n) {
  int ans = 0;
  while (n != 0) {
    n -= (n & -n);
    ++ans;
  }
  return ans;
}
long long mod = (long long)(1e9 + 7ll);
const int N = 1000100;
const int M = 10111;
const double eps = 1e-6;
using namespace std;
int g[101][101] = {0};
int a[101];
int main() {
  int n = nextInt(), m = nextInt();
  for (int i = 0; i < n; i++) a[i] = nextInt();
  for (int i = 0; i < m; i++) {
    int x = nextInt(), y = nextInt();
    --x, --y;
    g[x][y] = 1;
    g[y][x] = 1;
  }
  int ans = 5000000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i || g[i][j] != 1) continue;
      for (int k = 0; k < n; k++) {
        if (k == j || k == i || g[j][k] != 1 || g[i][k] != 1) continue;
        ans = min(ans, a[i] + a[j] + a[k]);
      }
    }
  }
  if (ans == 5000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
