#include <bits/stdc++.h>
using namespace std;
int n, m, a[500], f[500][500], ff[500][500], g[500][500], p[500][500], x[2000],
    y[2000], t[2000], b[500], s;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (f[x[i]][y[i]] == 0)
      t[i] = 1, f[x[i]][y[i]] = f[y[i]][x[i]] = 1,
      ff[x[i]][y[i]] = ff[y[i]][x[i]] = 1, b[x[i]] += a[y[i]],
      b[y[i]] += a[x[i]];
  }
  for (int i = 1; i <= m; i++)
    if (t[i]) {
      s = 0;
      for (int j = 1; j <= n; j++)
        if (f[x[i]][j] && f[j][y[i]]) s += a[j];
      g[x[i]][y[i]] += b[x[i]] + b[y[i]] - s,
          g[y[i]][x[i]] += b[x[i]] + b[y[i]] - s;
    }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (f[i][k] && f[k][j] && i != j && j != k && k != i) {
          f[i][j] = f[j][i] = 1;
          s = 0;
          for (int jj = 1; jj <= n; jj++)
            if (ff[i][jj] && ff[jj][j] && jj != k) s += a[jj];
          if (g[i][k] + g[k][j] - b[k] - a[k] - s < g[i][j] || g[i][j] == 0)
            g[i][j] = g[i][k] + g[k][j] - b[k] - a[k] - s;
        }
  printf("%d\n", g[1][n]);
}
