#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 20;
int n, m, adj[maxn][maxn], aa[maxn], ans = 1e9, x, y;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> aa[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    adj[x][y] = 1;
    adj[y][x] = 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      for (int a = j + 1; a <= n; a++)
        if (adj[i][j] && adj[a][j] && adj[i][a])
          ans = min(ans, aa[j] + aa[i] + aa[a]);
  ans == 1e9 ? cout << -1 : cout << ans;
}
