#include <bits/stdc++.h>
using namespace std;
int table[111][111];
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
      cin >> p[i];
    }
    memset(table, 0, sizeof(table));
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      table[u][v] = table[v][u] = 1;
    }
    long long mn = 1e10;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (i == j || j == k) {
            continue;
          }
          long long buf = p[i] + p[j] + p[k];
          if (table[i][j] == 1) {
            if (table[j][k] == 1) {
              if (table[k][i] == 1) {
                mn = min(buf, mn);
              }
            }
          }
        }
      }
    }
    if (mn == 1e10) {
      cout << -1 << endl;
    } else {
      cout << mn << endl;
    }
  }
}
