from collections import defaultdict import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) H = list(map(int, input().split())) G = [defaultdict(list), defaultdict(list)] for _ in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 G[0][x].append((y, max(H[y] - H[x], 0))) G[1][y].append((x, max(H[x] - H[y], 0))) DP = [[[-1, -1] for _ in range(n)] for _ in range(2)] DP[0][0][0] = 0 for i in range(n - 1): for j in range(2): if DP[0][i][j] != -1: for k, d in G[0][i]: if d > 0: if j == 0: DP[0][k][1] = max(DP[0][k][1], DP[0][i][j] + d) else: DP[0][k][0] = max(DP[0][k][0], DP[0][i][j]) print(max(DP[0][n - 1])) DP[1][n - 1][0] = 0 for i in range(n - 1, 0, -1): for j in range(2): if DP[1][i][j] != -1: for k, d in G[1][i]: if d > 0: if j == 0: DP[1][k][1] = max(DP[1][k][1], DP[1][i][j] + d) else: DP[1][k][0] = max(DP[1][k][0], DP[1][i][j]) print(max(DP[1][0])) if __name__ == '__main__': main()