#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    int val[102];
    for (int i = 1; i <= n; ++i) cin >> val[i];
    int mp[102][102] = {0};
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      mp[a][b] = mp[b][a] = 1;
    }
    int ans = 999999999;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n && j != i; ++j) {
        if (mp[i][j]) {
          for (int l = 1; l <= n && l != j && l != i; ++l) {
            if (mp[j][l] && mp[l][i]) {
              if (val[i] + val[j] + val[l] < ans)
                ans = val[i] + val[j] + val[l];
            }
          }
        }
      }
    }
    if (ans != 999999999)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
}
