#include <bits/stdc++.h>
using namespace std;
int n, m, g[111][111], a[111], S = int(1e9);
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x][y] = 1;
    g[y][x] = 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (g[i][j])
        for (int k = j + 1; k <= n; k++)
          if (g[i][k] && g[j][k]) S = min(a[i] + a[j] + a[k], S);
  if (S == int(1e9))
    cout << -1;
  else
    cout << S;
}
