#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, X, Y;
  int n, m, sum;
  cin >> n >> m;
  int A[n];
  for (i = 0; i < n; i++) cin >> A[i];
  bool AA[n][n];
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) AA[i][j] = false;
  for (i = 0; i < m; i++) {
    cin >> X >> Y;
    AA[X - 1][Y - 1] = true;
    AA[Y - 1][X - 1] = true;
  }
  sum = -10000;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      for (k = 0; k < n; k++)
        if (AA[i][j] && AA[j][k] && AA[i][k])
          if (sum < 0 || A[i] + A[j] + A[k] < sum) sum = A[i] + A[j] + A[k];
  if (sum < 0)
    cout << -1;
  else
    cout << sum;
}
