#include <bits/stdc++.h>
using namespace std;
int inf = 0x3f3f3f3f;
vector<vector<int>> g;
vector<int> c;
vector<int> used;
vector<int> dp;
vector<int> dp2;
void dfs(int v, int pred, int& otv) {
  dp.push_back(inf);
  dp2.push_back(1);
  int pos = upper_bound(dp.begin(), dp.end(), c[v]) - dp.begin();
  int val_pred1 = dp[pos], val_pred2 = dp2[pos];
  if (dp[pos - 1] < c[v] && c[v] < dp[pos]) {
    dp[pos] = c[v];
    dp2[pos] = dp2[pos - 1] + 1;
  }
  otv = max(otv, dp2[pos]);
  for (int to : g[v]) {
    if (to == pred) continue;
    dfs(to, v, otv);
  }
  dp[pos] = val_pred1;
  dp2[pos] = val_pred2;
  dp.pop_back();
  dp2.pop_back();
}
inline void solve() {
  int n;
  cin >> n;
  c.resize(n);
  g.resize(n);
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int otv = 0;
  for (int v = 0; v < n; v++) {
    used.assign(0, n);
    dp.clear();
    dp2.clear();
    dp.push_back(-inf);
    dp2.push_back(0);
    dfs(v, -1, otv);
  }
  cout << otv;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  for (; q > 0; q--) {
    solve();
    cout << '\n';
  }
}
