#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  bool match[n + 1][n + 1];
  memset(match, false, sizeof(match));
  while (m--) {
    int x, y;
    cin >> x >> y;
    match[x][y] = match[y][x] = true;
  }
  long long int ans = INT_MAX;
  bool f = false;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (!(match[i][j] || match[j][i])) continue;
      for (int k = j + 1; k <= n; k++) {
        if (!(match[j][k] || match[k][j])) continue;
        if (!(match[i][k] || match[k][i])) continue;
        f = true;
        ans = min(ans, arr[i] + arr[j] + arr[k]);
      }
    }
  }
  if (f)
    cout << ans;
  else
    cout << "-1";
}
