#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int &i : a) {
    cin >> i;
  }
  vector<vector<bool> > match(n + 1, vector<bool>(n + 1, false));
  for (int i = 0, x, y; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    match[x][y] = true;
    match[y][x] = true;
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int z = j + 1; z < n; z++) {
        if (match[i][j] && match[j][z] && match[z][i]) {
          ans = min(ans, a[i] + a[j] + a[z]);
        }
      }
    }
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans << '\n';
  return 0;
}
