const
  MAXN = 100;
  MAXM = 1000;
  MAXT = 1000;
var
  max, sum, n, m, i, a, b : integer;
  t : array[1..MAXN] of integer;
  q : array[1..MAXN] of boolean;
  k : integer;
  ed, next : array[1..MAXM] of integer;
  beg : array[1..MAXN] of integer;
  c: array[1..MAXN] of integer;

procedure dfs(i : integer);
var
  j : integer;
begin
  c[i] := 1;
  j := beg[i];
  while (j <> 0) do begin
    assert(c[ed[j]] <> 1);
    if (c[ed[j]] = 0) then begin
      dfs(ed[j]);
    end;
    j := next[j];
  end;
  c[i] := 2;
end;

procedure add(a, b : integer);
begin
  k := k + 1;
  ed[k] := b;
  next[k] := beg[a];
  beg[a] := k;
end;

begin
  reset(input, 'homework.in');
  rewrite(output, 'homework.out');
  read(n, m);
  assert((1 <= n) and (n <= MAXN));
  assert((0 <= m) and (m <= MAXM));
  sum := 0;
  for i := 1 to n do begin
    read(t[i]);
    assert((1 <= t[i]) and (t[i] <= MAXT));
    sum := sum + t[i];
  end;
  k := 0;
  for i := 1 to m do begin
    read(a, b);
    assert((1 <= a) and (a <= MAXN));
    assert((1 <= b) and (b <= MAXN));
    assert(a <> b);
    add(a, b);
    q[a] := true;
  end;
  for i := 1 to n do begin
    if (c[i] = 0) then begin
      dfs(i);
    end;
  end;
  max := 0;
  for i := 1 to n do begin
    if (not(q[i])) and (t[i] > max) then begin
      max := t[i];
    end;
  end;
  writeln(sum - max);
end.