#include using namespace std; using ll = long long; int main () { int N, M; cin >> N >> M; ll H[200020]; for (int i = 0; i < N; i ++) { cin >> H[i]; } vector gr[100010]; for (int i = 0; i < M; i ++) { int a, b; cin >> a >> b; gr[--a].push_back(--b); gr[b].push_back(a); } ll dp1[100010][2], dp2[100010][2]; for (int i = 0; i < N; i ++) { for (int j = 0; j < 2; j ++) { dp1[i][j] = dp2[i][j] = -1; } } dp1[0][0] = dp1[0][1] = dp2[N-1][0] = dp2[N-1][1] = 0; for (int i = 0; i < N - 1; i ++) { for (int j = 0; j < 2; j ++) { for (auto v : gr[i]) { if (H[v] > H[i] && j) { continue; } if (v <= i) { continue; } int p = H[v] > H[i]; dp1[v][p] = max(dp1[v][p], dp1[i][j] + max(0ll, H[v] - H[i])); } } } for (int i = N - 1; i > 0; i --) { for (int j = 0; j < 2; j ++) { for (auto v : gr[i]) { if (H[v] > H[i] && j) { continue; } if (v >= i) { continue; } int p = H[v] > H[i]; dp2[v][p] = max(dp2[v][p], dp2[i][j] + max(0ll, H[v] - H[i])); } } } cout << max(dp1[N-1][0], dp1[N-1][1]) << '\n' << max(dp2[0][0], dp2[0][1]) << endl; }