#include <bits/stdc++.h>
using namespace std;
bool g[107][107];
int n, m, p[107];
int find(int x) {
  int ans = 1e8 + 9;
  for (int i = 1; i <= n; ++i) {
    if (!g[x][i]) continue;
    int d = i;
    for (int j = 1; j <= n; ++j) {
      if (!g[d][j]) continue;
      int b = j;
      if (g[b][x] && p[x] + p[d] + p[b] < ans) ans = p[x] + p[d] + p[b];
    }
  }
  return ans;
}
int main() {
  while (cin >> n >> m) {
    memset(g, false, sizeof(g));
    for (int i = 1; i <= n; ++i) cin >> p[i];
    for (int i = 0, a, b; i < m; ++i) {
      cin >> a >> b;
      g[a][b] = true;
      g[b][a] = true;
    }
    int as = 1e8 + 9;
    for (int i = 1; i <= n; ++i) {
      int t = find(i);
      if (as > t) as = t;
    }
    if (as == 1e8 + 9)
      cout << -1 << endl;
    else
      cout << as << endl;
  }
  return 0;
}
