#include <bits/stdc++.h>
using namespace std;
struct vertex {
  int price;
  int color;
};
const int MAX = 100 + 10;
int n;
int m;
vertex v[MAX];
vector<int> e[MAX];
int Min = 10000000;
int main() {
  cin >> n;
  cin >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].price;
  }
  for (int i = 1; i <= m; i++) {
    int x;
    int y;
    cin >> x;
    cin >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < e[i].size(); j++) {
      v[e[i][j]].color = 1;
    }
    for (int j = 0; j < e[i].size(); j++) {
      for (int k = 0; k < e[e[i][j]].size(); k++) {
        if (v[e[e[i][j]][k]].color == 1) {
          Min = min(Min,
                    (v[i].price + v[e[i][j]].price + v[e[e[i][j]][k]].price));
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      v[j].color = 0;
    }
  }
  if (Min == 10000000) {
    Min = -1;
  }
  cout << Min;
}
