#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> as;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    as.push_back(tmp);
  }
  bool matches[101][101];
  memset(matches, false, sizeof(matches));
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    matches[u][v] = true;
    matches[v][u] = true;
  }
  int result = INT_MAX;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      for (int k = j + 1; k <= n; k++) {
        if (matches[i][j] && matches[j][k] && matches[k][i]) {
          result = min(result, as[i - 1] + as[j - 1] + as[k - 1]);
        }
      }
    }
  }
  if (result == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}
