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