#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool sovm[n][n];
  int cost[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) sovm[i][j] = false;
    cin >> cost[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    sovm[a][b] = true;
    sovm[b][a] = true;
  }
  int ans = 1000000000;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++) {
        if (sovm[i][j] && sovm[i][k] && sovm[j][k]) {
          ans = min(ans, cost[i] + cost[j] + cost[k]);
        }
      }
  if (ans == 1000000000) ans = -1;
  cout << ans << endl;
  return 0;
}
