#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, ct[N], a[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> ct[i];
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    a[x][y] = a[y][x] = 1;
  }
  int ans = 1 << 30;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      for (int k = j + 1; k <= n; ++k)
        if (a[i][j] && a[j][k] && a[i][k])
          ans = min(ans, ct[i] + ct[j] + ct[k]);
  ans = ans == 1 << 30 ? -1 : ans;
  cout << ans << '\n';
}
