#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = INT_MAX;
  bool sl = 0;
  scanf("%I32d %I32d", &n, &m);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%I32d", &a[i]);
  deque<pair<int, int> > dq(m);
  deque<deque<int> > df(n + 1);
  for (int i = 0; i < m; i++)
    scanf("%I32d %I32d", &dq[i].first, &dq[i].second),
        df[dq[i].first].push_back(dq[i].second),
        df[dq[i].second].push_back(dq[i].first);
  for (int i = 0; i < m; i++) {
    deque<int> first = df[dq[i].first], second = df[dq[i].second];
    for (int h = 0; h < first.size(); h++)
      for (int j = 0; j < second.size(); j++)
        if (first[h] == second[j])
          ans = min(ans,
                    a[dq[i].first - 1] + a[dq[i].second - 1] + a[first[h] - 1]),
          sl = 1;
  }
  (sl) ? printf("%I32d\n", ans) : puts("-1");
}
