import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class homework_sm {

	void solve() {
		int n = in.nextInt();
		myAssert(1 <= n && n <= 100);
		int m = in.nextInt();
		myAssert(0 <= m && m <= 1000);
		int[] t = new int[n];
		for (int i = 0; i < t.length; i++) {
			t[i] = in.nextInt();
			myAssert(1 <= t[i] && t[i] <= 1000);
		}
		boolean[][] before = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int a = in.nextInt();
			myAssert(1 <= a && a <= n);
			int b = in.nextInt();
			myAssert(1 <= b && b <= n);
			before[a - 1][b - 1] = true;
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					before[i][j] |= before[i][k] && before[k][j];
				}
			}
		}
		for (int i = 0; i < before.length; i++) {
			myAssert(!before[i][i]);
		}
		int dont_do = 0;
		int sum = 0;
		fori: for (int i = 0; i < n; i++) {
			sum += t[i];
			for (int j = 0; j < n; j++) {
				if (before[i][j])
					continue fori;
			}
			dont_do = Math.max(dont_do, t[i]);
		}
		out.println(sum - dont_do);
	}

	void myAssert(boolean b) {
		if (!b) {
			throw new AssertionError();
		}
	}

	PrintWriter out;
	Scanner in;

	public void run() {
		try {
			in = new Scanner(new File("homework.in"));
			out = new PrintWriter("homework.out");
			solve();
			out.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) {
		new homework_sm().run();
	}
}
