#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> items;
bool check(int counter, int i, int j) {
  int sizeI = items[i].size();
  for (int counter2 = 0; counter2 < sizeI; counter2++) {
    if (items[i][counter2] == j) return true;
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  int prices[N + 1];
  for (int counter = 1; counter <= N; counter++) {
    cin >> prices[counter];
  }
  for (int counter = 0; counter < N + 2; counter++) {
    vector<int> emptyV;
    items.push_back(emptyV);
  }
  for (int counter = 0; counter < M; counter++) {
    int x, y;
    cin >> x >> y;
    items[x].push_back(y);
    items[y].push_back(x);
  }
  int minP = INT_MAX;
  bool found = false;
  for (int counter = 1; counter <= N; counter++) {
    int dVsize = items[counter].size();
    if (dVsize >= 2) {
      for (int i = 0; i < dVsize; i++) {
        for (int j = i + 1; j < dVsize; j++) {
          int sum = prices[counter] + prices[(int)items[counter][j]] +
                    prices[(int)items[counter][i]];
          if (sum < minP) {
            if (check(counter, items[counter][i], items[counter][j])) {
              found = true;
              minP = sum;
            }
          }
        }
      }
    }
  }
  if (found) {
    cout << minP << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
