#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long gf = 1e6 + 9;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  map<pair<long long, long long>, long long> m1;
  long long n, m;
  cin >> n >> m;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    m1[{x, y}]++;
    m1[{y, x}]++;
  }
  long long ans = (1e9 + 5);
  for (long long i = 1; i <= n; i++) {
    for (long long j = i + 1; j <= n; j++) {
      for (long long k = j + 1; k <= n; k++) {
        if (m1[{i, j}] && m1[{j, k}] && m1[{i, k}]) {
          ans = min(ans, a[i] + a[j] + a[k]);
        }
      }
    }
  }
  if (ans == (1e9 + 5))
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
