#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, v[6002], v2[6002], aint[30002], poz[6002];
int ans;
vector<int> vv[6002];
void update(int nod, int st, int dr, int poz, int val) {
  if (st == dr) {
    aint[nod] = val;
    return;
  }
  int mid = (st + dr) / 2;
  if (poz <= mid)
    update(nod << 1, st, mid, poz, val);
  else
    update(nod << 1 | 1, mid + 1, dr, poz, val);
  aint[nod] = max(aint[nod << 1], aint[nod << 1 | 1]);
}
int fndval(int nod, int st, int dr, int plc) {
  if (st == dr) return nod;
  int mid = (st + dr) / 2;
  if (plc <= mid) return fndval(nod << 1, st, mid, plc);
  return fndval(nod << 1 | 1, mid + 1, dr, plc);
}
int query(int nod, int st, int dr, int L, int R) {
  if (R < L) return 0;
  if (L <= st && dr <= R) return aint[nod];
  if (dr < L || st > R) return -1;
  int mid = (st + dr) / 2;
  return max(query(nod << 1, st, mid, L, R),
             query(nod << 1 | 1, mid + 1, dr, L, R));
}
void dfs(int dad, int nod) {
  int old = aint[poz[v[nod]]];
  int xx = query(1, 1, n, 1, v[nod] - 1) + 1;
  ans = max(ans, xx);
  if (xx > old) update(1, 1, n, v[nod], xx);
  for (int i = 0; i < vv[nod].size(); ++i) {
    int vecin = vv[nod][i];
    if (vecin == dad) continue;
    dfs(nod, vecin);
  }
  if (xx > old) update(1, 1, n, v[nod], old);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> v[i], v2[i] = v[i];
  sort(v2 + 1, v2 + n + 1);
  for (int i = 1; i <= n; ++i) {
    int st = 1;
    int dr = n;
    int ans = 0;
    while (st <= dr) {
      int mid = (st + dr) / 2;
      if (v2[mid] < v[i])
        st = mid + 1;
      else
        ans = mid, dr = mid - 1;
    }
    v[i] = ans;
  }
  for (int i = 1; i <= n; ++i) poz[i] = fndval(1, 1, n, i);
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    vv[a].push_back(b);
    vv[b].push_back(a);
  }
  vector<int> vvv;
  for (int i = 1; i <= n; ++i) vvv.push_back(i);
  random_shuffle(vvv.begin(), vvv.end());
  for (int i = 0; i < min(n, 2500); ++i) dfs(0, vvv[i]);
  cout << ans;
  return 0;
}
