#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5;
vector<int> G[MAXN];
int happiness[MAXN], f[MAXN], tmpAns = 0, ans = 0;
void dfs(int u, int par) {
  int oldTmpAns = -1, oldF = -1, oldFPos = -1;
  if (~par && f[tmpAns] < happiness[u])
    oldTmpAns = tmpAns, f[++tmpAns] = happiness[u];
  else {
    int pos = lower_bound(f, f + tmpAns, happiness[u]) - f;
    oldF = f[pos], oldFPos = pos;
    f[pos] = happiness[u];
  }
  ans = max(ans, tmpAns);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == par) continue;
    dfs(v, u);
  }
  if (oldTmpAns != -1) tmpAns = oldTmpAns;
  if (oldF != -1) f[oldFPos] = oldF;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> happiness[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    f[0] = happiness[i];
    tmpAns = 0;
    dfs(i, -1);
  }
  cout << ans + 1 << endl;
  return 0;
}
