#include <bits/stdc++.h>
using namespace std;
std::vector<vector<int> > g;
int cst[110];
int num[110], p[110];
int ans = -1;
void solve(int u) {
  num[u] = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (num[v] == -1) {
      p[v] = u;
      solve(v);
    } else if (num[v] == 0) {
      if (p[u] != v) {
        int csts = 0;
        int count = 0;
        int current = u;
        int end = v;
        while (true) {
          csts += cst[current];
          count++;
          if (current == v || current == p[current]) break;
          current = p[current];
        }
        if (count == 3) {
          if (ans == -1)
            ans = csts;
          else
            ans = min(ans, csts);
        }
      }
    }
  }
  num[u] = 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> cst[i];
  g.assign(n, vector<int>());
  for (int i = 0; i < n; i++) p[i] = i;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    memset(num, -1, sizeof num);
    solve(i);
  }
  cout << ans << endl;
  return 0;
}
