#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
priority_queue<int, vector<int>, greater<int> > q[200];
vector<int> ma[200];
int c[200];
int pa, wa;
void dfs(int now, int step, int sum) {
  int i, l = ma[now].size();
  if (step == 4) {
    if (now == pa) {
      wa = min(wa, sum);
    }
    return;
  }
  for (i = 0; i < l; i++) {
    dfs(ma[now][i], step + 1, sum + c[now]);
  }
}
int main() {
  int n, m, i, j, u, v;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    ma[u].push_back(v);
    ma[v].push_back(u);
  }
  wa = inf;
  for (pa = 1; pa <= n; pa++) {
    dfs(pa, 1, 0);
  }
  printf("%d\n", wa == inf ? -1 : wa);
}
