Problem: The biggest gold mine in Berland consists of n caves, connected by n - 1 transitions. The entrance to the mine leads to the cave number 1, it is possible to go from it to any remaining cave of the mine by moving along the transitions. 

The mine is being developed by the InMine Inc., k miners work for it. Each day the corporation sorts miners into caves so that each cave has at most one miner working there. 

For each cave we know the height of its ceiling hi in meters, and for each miner we know his height sj, also in meters. If a miner's height doesn't exceed the height of the cave ceiling where he is, then he can stand there comfortably, otherwise, he has to stoop and that makes him unhappy.

Unfortunately, miners typically go on strike in Berland, so InMine makes all the possible effort to make miners happy about their work conditions. To ensure that no miner goes on strike, you need make sure that no miner has to stoop at any moment on his way from the entrance to the mine to his cave (in particular, he must be able to stand comfortably in the cave where he works). 

To reach this goal, you can choose exactly one cave and increase the height of its ceiling by several meters. However enlarging a cave is an expensive and complex procedure. That's why InMine Inc. asks you either to determine the minimum number of meters you should raise the ceiling of some cave so that it is be possible to sort the miners into the caves and keep all miners happy with their working conditions or to determine that it is impossible to achieve by raising ceiling in exactly one cave.

Input

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of caves in the mine.

Then follows a line consisting of n positive integers h1, h2, ..., hn (1 ≤ hi ≤ 109), where hi is the height of the ceiling in the i-th cave.

Next n - 1 lines contain the descriptions of transitions between the caves. Each line has the form ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the numbers of the caves connected by a path.

The next line contains integer k (1 ≤ k ≤ n).

The last line contains k integers s1, s2, ..., sk (1 ≤ sj ≤ 109), where sj is the j-th miner's height.

Output

In the single line print the minimum number of meters that you need to raise the ceiling by in some cave so that all miners could be sorted into caves and be happy about the work conditions. If it is impossible to do, print  - 1. If it is initially possible and there's no need to raise any ceiling, print 0. 

Examples

Input

6
5 8 4 6 3 12
1 2
1 3
4 2
2 5
6 3
6
7 4 2 5 3 11


Output

6


Input

7
10 14 7 12 4 50 1
1 2
2 3
2 4
5 1
6 5
1 7
6
7 3 4 8 8 10


Output

0


Input

3
4 2 8
1 2
1 3
2
17 15


Output

-1

Note

In the first sample test we should increase ceiling height in the first cave from 5 to 11. After that we can distribute miners as following (first goes index of a miner, then index of a cave): <image>.

In the second sample test there is no need to do anything since it is already possible to distribute miners as following: <image>.

In the third sample test it is impossible.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 3;
const int TR = 2097162;
const int LN = 20;
const int oo = 1e9;
int h[N], s[N], ht[N], tr[TR], add[TR], st[N + N], pr[N][LN], mn[N][LN],
    zn[N + N], gg[N];
bool cl[N];
vector<int> df, g[N], a[N];
void dfs() {
  int i, t, u, j, v, z1, z2, pl;
  df.push_back(0);
  pr[0][1] = 0;
  for (t = 0; t < (int)df.size(); ++t) {
    i = df[t];
    cl[i] = true;
    pr[i][0] = i;
    for (j = 2; j < LN; ++j) pr[i][j] = pr[pr[i][j - 1]][j - 1];
    mn[i][0] = i;
    for (j = 1; j < LN; ++j) {
      z1 = mn[i][j - 1];
      z2 = mn[pr[pr[i][j - 1]][1]][j - 1];
      if (h[z2] <= h[z1])
        mn[i][j] = z2;
      else
        mn[i][j] = z1;
    }
    z1 = mn[i][LN - 1];
    if (h[z1] < h[i]) {
      z2 = i;
      v = pr[i][1];
      for (pl = 0; ht[pr[v][pl]] > ht[z1]; ++pl)
        ;
      while (true) {
        while ((pl >= 0) && (ht[pr[v][pl]] <= ht[z1])) --pl;
        if (pl < 0) break;
        if (h[z2] >= h[mn[v][pl]]) z2 = mn[v][pl];
        v = pr[pr[v][pl]][1];
      }
      a[z1].push_back(h[z2]);
      gg[i] = -1;
    } else {
      if (i)
        gg[i] = h[mn[pr[i][1]][LN - 1]];
      else
        gg[i] = -1;
    }
    for (u = 0; u < (int)g[i].size(); ++u) {
      j = g[i][u];
      if (cl[j]) continue;
      ht[j] = ht[i] + 1;
      pr[j][1] = i;
      df.push_back(j);
    }
  }
}
void change(int i, int lt, int rt, int l, int r, int c) {
  if (l > r) return;
  if ((lt == l) && (rt == r)) {
    add[i] += c;
    return;
  }
  int x = (lt + rt) >> 1;
  change(i << 1, lt, x, l, min(x, r), c);
  change((i << 1) + 1, x + 1, rt, max(x + 1, l), r, c);
  tr[i] = max(tr[i << 1] + add[i << 1], tr[(i << 1) + 1] + add[(i << 1) + 1]);
}
int get(int i, int lt, int rt, int l, int r) {
  if (l > r) return -oo;
  if ((lt == l) && (rt == r)) return tr[i] + add[i];
  int z1, z2, x = (lt + rt) >> 1;
  z1 = get(i << 1, lt, x, l, min(x, r));
  z2 = get((i << 1) + 1, x + 1, rt, max(l, x + 1), r);
  return max(z1, z2) + add[i];
}
vector<int> pp;
int main() {
  if (0) {
    freopen("input.txt", "w", stdout);
    int n, i, k;
    n = 5e5;
    printf("%d\n", n);
    for (i = 0; i < n; ++i) printf("%d ", n - i);
    printf("\n");
    for (i = 0; i < n - 1; ++i) {
      printf("%d %d\n", i + 1, i + 2);
    }
    k = 5e5;
    printf("%d\n", k);
    for (i = 0; i < n; ++i) printf("%d ", rand() % oo + 1);
    printf("\n");
    return 0;
  }
  int i, j, u, n, m, k, ans, mx, sz;
  map<int, int> mp;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", &h[i]);
  for (u = 0; u < n - 1; ++u) {
    scanf("%d%d", &i, &j);
    --i;
    --j;
    g[i].push_back(j);
    g[j].push_back(i);
  }
  scanf("%d", &k);
  for (i = 0; i < k; ++i) scanf("%d", &s[i]);
  sort(s, s + k);
  for (i = 0; i < n; ++i) st[i] = h[i];
  for (i = 0; i < k; ++i) st[n + i] = s[i];
  sort(st, st + n + k);
  m = 0;
  for (i = 0; i < n + k; ++i)
    if (!i || (st[i - 1] != st[i])) {
      mp[st[i]] = m;
      zn[m++] = st[i];
    }
  for (i = 0; i < n; ++i) h[i] = mp[h[i]];
  for (i = 0; i < k; ++i) s[i] = mp[s[i]];
  for (i = 0; i < n; ++i) cl[i] = false;
  ht[0] = 0;
  dfs();
  for (i = 0; i < n; ++i) sort(a[i].begin(), a[i].end());
  for (sz = 1; sz < m; sz <<= 1)
    ;
  for (i = 0; i < sz; ++i) add[i] = tr[i] = 0;
  for (i = 0; i < k; ++i) ++tr[sz + s[i]];
  for (i = sz - 2; i >= 0; --i) tr[sz + i] += tr[sz + i + 1];
  for (i = sz - 1; i > 0; --i) tr[i] = max(tr[i << 1], tr[(i << 1) + 1]);
  for (i = 0; i < n; ++i) change(1, 0, sz - 1, 0, h[mn[i][LN - 1]], -1);
  mx = -1;
  for (i = 0; i < m; ++i)
    if (get(1, 0, sz - 1, i, i) > 0) mx = i;
  if (get(1, 0, sz - 1, 0, sz - 1) <= 0) {
    printf("0\n");
    return 0;
  }
  ans = oo;
  gg[0] = m - 1;
  for (i = 1; i < n; ++i) gg[i] = h[mn[pr[i][1]][LN - 1]];
  for (i = 0; i < n; ++i) {
    if (gg[i] < mx) continue;
    change(1, 0, sz - 1, h[i] + 1, mx, -1);
    for (u = 0; u < (int)a[i].size(); ++u)
      if (a[i][u] < mx)
        change(1, 0, sz - 1, h[i] + 1, a[i][u], -1);
      else
        change(1, 0, sz - 1, h[i] + 1, mx, -1);
    if (get(1, 0, sz - 1, 0, sz - 1) <= 0) ans = min(ans, zn[mx] - zn[h[i]]);
    for (u = 0; u < (int)a[i].size(); ++u)
      if (a[i][u] < mx)
        change(1, 0, sz - 1, h[i] + 1, a[i][u], 1);
      else
        change(1, 0, sz - 1, h[i] + 1, mx, 1);
    change(1, 0, sz - 1, h[i] + 1, mx, +1);
  }
  if (ans == oo) ans = -1;
  printf("%d\n", ans);
  ans = oo;
  return 0;
}