#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T &x) {
  return x * x;
}
inline long long sqr(int x) { return sqr<long long>(x); }
template <class T>
T binpow(const T &a, long long n) {
  return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1);
}
long long binpow(long long a, long long n, long long modulo) {
  return n == 0 ? 1
                : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) %
                      modulo;
}
long long gcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
inline long long phi(long long n) {
  long long result = n;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  if (n > 1) result -= result / n;
  return result;
}
inline vector<long long> inverseAll(long long m) {
  vector<long long> r(m);
  r[1] = 1;
  for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m;
  return r;
}
inline long long gcd(long long a, long long b) { return gcd(a, b, a, b); }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long llrand() {
  const long long lsbToFill = (sizeof(long long) << 3) - 1;
  const long long bitsFilledInIteration = __builtin_popcountll(RAND_MAX);
  long long number = 0;
  for (long long lsbFilled = 0; lsbFilled <= lsbToFill;
       lsbFilled += bitsFilledInIteration) {
    number ^= (((long long)rand()) << lsbFilled);
  }
  return number & numeric_limits<long long>::max();
}
inline long long llrand(long long begin, long long end) {
  return begin + llrand() % (end - begin);
}
struct Dinic {
  struct Edge {
    int u, v;
    long long cap, flow;
    Edge() {}
    Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
  };
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
  void AddEdge(int u, int v, long long cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }
  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == T) break;
      for (int k : g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }
  long long DFS(int u, int T, long long flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i] ^ 1];
      if (d[e.v] == d[e.u] + 1) {
        long long amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (long long pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  long long MaxFlow(int S, int T) {
    long long total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (long long flow = DFS(S, T)) total += flow;
    }
    return total;
  }
};
vector<long long> Dijkstra(const vector<list<pair<int, long long>>> &g, int s) {
  vector<long long> d(int((g).size()), numeric_limits<long long>::max() / 2LL);
  priority_queue<pair<long long, int>> q;
  d[s] = 0;
  q.emplace(-0, s);
  while (!q.empty()) {
    while (q.top().first > d[q.top().second]) {
      q.pop();
    }
    int v = q.top().second;
    q.pop();
    for (const auto &cw : g[v]) {
      if (d[v] + cw.second < d[cw.first]) {
        d[cw.first] = d[v] + cw.second;
        q.emplace(-d[cw.first], cw.first);
      }
    }
  }
  return d;
}
struct BinarySearchIterator
    : public std::iterator<std::forward_iterator_tag, bool> {
  long long value;
  typename iterator_traits<BinarySearchIterator>::difference_type operator-(
      const BinarySearchIterator &it) const {
    return value - it.value;
  }
  BinarySearchIterator &operator++() {
    ++value;
    return *this;
  }
  bool operator!=(const BinarySearchIterator &it) const {
    return value != it.value;
  }
  bool operator*() const { return true; }
};
template <int ALPHA>
class AhoCorasick {
 public:
  static const int ILLEGAL_INDEX;
  static const int ROOT;
  struct Node {
    bool leaf;
    int parent;
    int parentCharacter;
    int link;
    int next[ALPHA];
    int go[ALPHA];
    int outputFunction;
    Node(int parent = ILLEGAL_INDEX, int parentCharacter = ALPHA)
        : leaf(false),
          parent(parent),
          parentCharacter(parentCharacter),
          link(ILLEGAL_INDEX),
          outputFunction(ILLEGAL_INDEX) {
      fill_n(next, ALPHA, ILLEGAL_INDEX);
      fill_n(go, ALPHA, ILLEGAL_INDEX);
    }
  };
  vector<Node> tree = vector<Node>(1);
  AhoCorasick() {}
  AhoCorasick(int maxStatesNumber) { tree.reserve(maxStatesNumber); }
  template <class Iterator>
  void add(int length, const Iterator begin) {
    int vertex = ROOT;
    for (int i = 0; i < length; ++i) {
      if (ILLEGAL_INDEX == tree[vertex].next[begin[i]]) {
        tree[vertex].next[begin[i]] = int((tree).size());
        tree.push_back(Node(vertex, begin[i]));
      }
      vertex = tree[vertex].next[begin[i]];
    }
    tree[vertex].leaf = true;
  }
  int getLink(int vertex) {
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].link) {
      if (ROOT == vertex || ROOT == tree[vertex].parent) {
        tree[vertex].link = ROOT;
      } else {
        tree[vertex].link =
            go(getLink(tree[vertex].parent), tree[vertex].parentCharacter);
      }
    }
    return tree[vertex].link;
  }
  int go(int vertex, int character) {
    assert(0 <= character && character < ALPHA);
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].go[character]) {
      if (ILLEGAL_INDEX == tree[vertex].next[character]) {
        tree[vertex].go[character] =
            ROOT == vertex ? ROOT : go(getLink(vertex), character);
      } else {
        tree[vertex].go[character] = tree[vertex].next[character];
      }
    }
    return tree[vertex].go[character];
  }
  int getOutputFunction(int vertex) {
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].outputFunction) {
      if (tree[vertex].leaf || ROOT == vertex) {
        tree[vertex].outputFunction = vertex;
      } else {
        tree[vertex].outputFunction = getOutputFunction(getLink(vertex));
      }
    }
    return tree[vertex].outputFunction;
  }
};
template <int ALPHA>
const int AhoCorasick<ALPHA>::ILLEGAL_INDEX = -1;
template <int ALPHA>
const int AhoCorasick<ALPHA>::ROOT = 0;
vector<list<int>> g;
vector<int> is_max;
pair<int, int> dfs(int vertex) {
  int total = 0;
  int min_after = int((g).size()) + 1;
  int total_before = 0;
  for (int child : g[vertex]) {
    auto index_size = dfs(child);
    min_after = min(index_size.second - index_size.first, min_after);
    total_before += index_size.first;
    total += index_size.second;
  }
  int index;
  if (g[vertex].empty()) {
    index = 0;
    total = 1;
  } else if (is_max[vertex]) {
    index = total - min_after;
  } else {
    index = total_before;
  }
  assert(0 <= index);
  assert(index < total);
  return make_pair((index), (total));
}
void build_graph(const vector<int> &f) {
  const int n = int((f).size()) + 1;
  g.assign(n, list<int>());
  for (int i = (1); i < (n); ++i) {
    g[f[i - 1]].push_back(i);
  }
}
int solve(const vector<int> &f) {
  build_graph(f);
  auto index_size = dfs(0);
  return index_size.first;
}
vector<int> generate() {
  int n = 2 + rand() % 8;
  vector<int> f(n - 1);
  for (int i = (0); i < (n - 1); ++i) {
    f[i] = rand() % (i + 1);
  }
  is_max.resize(n);
  for (int i = (0); i < (n); ++i) {
    is_max[i] = rand() % 2;
  }
  return f;
}
int dfs(int vertex, const vector<int> &order, int &index) {
  if (g[vertex].empty()) {
    return order[index++];
  }
  int answer = is_max[vertex] ? -1 : int((order).size());
  for (int child : g[vertex]) {
    int current = dfs(child, order, index);
    if (is_max[vertex]) {
      answer = max(answer, current);
    } else {
      answer = min(answer, current);
    }
  }
  return answer;
}
int bf(const vector<int> &f) {
  int n = int((f).size()) + 1;
  build_graph(f);
  vector<int> leaves;
  for (int i = (0); i < (n); ++i) {
    if (g[i].empty()) {
      leaves.push_back((i));
    }
  }
  vector<int> order(int((leaves).size()));
  for (int i = (0); i < (int((order).size())); ++i) {
    order[i] = i;
  }
  int answer = -1;
  do {
    int index = 0;
    int current = dfs(0, order, index);
    assert(index == int((order).size()));
    if (current > answer) {
      answer = current;
    }
  } while (next_permutation((order).begin(), (order).end()));
  return answer;
}
void stress() {
  is_max = {1, 0, 1, 1, 0, 1};
  assert(0 == solve({0, 1, 1, 1, 1}));
  {
    is_max = {0, 1, 1, 1, 1, 0, 0};
    auto a = solve({0, 1, 1, 0, 4, 4});
    assert(2 == a);
  }
  is_max = {1, 0, 1, 0, 1};
  assert(3 == bf({0, 0, 0, 0}));
  assert(3 == solve({0, 0, 0, 0}));
  is_max = {1, 0, 0, 1, 0, 1, 1, 0};
  assert(3 == bf({0, 0, 1, 1, 2, 2, 2}));
  assert(3 == solve({0, 0, 1, 1, 2, 2, 2}));
  is_max = {1, 1, 0, 0, 1, 0, 1, 0, 1};
  assert(4 == bf({0, 0, 1, 1, 2, 2, 3, 3}));
  assert(4 == solve({0, 0, 1, 1, 2, 2, 3, 3}));
  while (true) {
    auto f = generate();
    auto o = solve(f);
    auto a = bf(f);
    assert(a == o);
    cerr << "OK" << endl;
  }
}
int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  srand((unsigned int)time(NULL));
  int n;
  while (cin >> n) {
    is_max.resize(n);
    for (int i = (0); i < (n); ++i) {
      cin >> is_max[i];
    }
    vector<int> f(n - 1);
    for (int i = (1); i < (n); ++i) {
      cin >> f[i - 1];
      --f[i - 1];
    }
    cout << 1 + solve(f) << endl;
  }
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. 

As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a node v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all nodes for which v is the parent. A vertex is a leaf if it has no children.

The rooted tree Serval owns has n nodes, node 1 is the root. Serval will write some numbers into all nodes of the tree. However, there are some restrictions. Each of the nodes except leaves has an operation max or min written in it, indicating that the number in this node should be equal to the maximum or minimum of all the numbers in its sons, respectively. 

Assume that there are k leaves in the tree. Serval wants to put integers 1, 2, …, k to the k leaves (each number should be used exactly once). He loves large numbers, so he wants to maximize the number in the root. As his best friend, can you help him?

Input

The first line contains an integer n (2 ≤ n ≤ 3⋅ 10^5), the size of the tree.

The second line contains n integers, the i-th of them represents the operation in the node i. 0 represents min and 1 represents max. If the node is a leaf, there is still a number of 0 or 1, but you can ignore it.

The third line contains n-1 integers f_2, f_3, …, f_n (1 ≤ f_i ≤ i-1), where f_i represents the parent of the node i.

Output

Output one integer — the maximum possible number in the root of the tree.

Examples

Input


6
1 0 1 1 0 1
1 2 2 2 2


Output


1


Input


5
1 0 1 0 1
1 1 1 1


Output


4


Input


8
1 0 0 1 0 1 1 0
1 1 2 2 3 3 3


Output


4


Input


9
1 1 0 0 1 0 1 0 1
1 1 2 2 3 3 4 4


Output


5

Note

Pictures below explain the examples. The numbers written in the middle of the nodes are their indices, and the numbers written on the top are the numbers written in the nodes.

In the first example, no matter how you arrange the numbers, the answer is 1.

<image>

In the second example, no matter how you arrange the numbers, the answer is 4.

<image>

In the third example, one of the best solution to achieve 4 is to arrange 4 and 5 to nodes 4 and 5.

<image>

In the fourth example, the best solution is to arrange 5 to node 5.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T &x) {
  return x * x;
}
inline long long sqr(int x) { return sqr<long long>(x); }
template <class T>
T binpow(const T &a, long long n) {
  return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1);
}
long long binpow(long long a, long long n, long long modulo) {
  return n == 0 ? 1
                : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) %
                      modulo;
}
long long gcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
inline long long phi(long long n) {
  long long result = n;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  if (n > 1) result -= result / n;
  return result;
}
inline vector<long long> inverseAll(long long m) {
  vector<long long> r(m);
  r[1] = 1;
  for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m;
  return r;
}
inline long long gcd(long long a, long long b) { return gcd(a, b, a, b); }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long llrand() {
  const long long lsbToFill = (sizeof(long long) << 3) - 1;
  const long long bitsFilledInIteration = __builtin_popcountll(RAND_MAX);
  long long number = 0;
  for (long long lsbFilled = 0; lsbFilled <= lsbToFill;
       lsbFilled += bitsFilledInIteration) {
    number ^= (((long long)rand()) << lsbFilled);
  }
  return number & numeric_limits<long long>::max();
}
inline long long llrand(long long begin, long long end) {
  return begin + llrand() % (end - begin);
}
struct Dinic {
  struct Edge {
    int u, v;
    long long cap, flow;
    Edge() {}
    Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
  };
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
  void AddEdge(int u, int v, long long cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }
  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == T) break;
      for (int k : g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }
  long long DFS(int u, int T, long long flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i] ^ 1];
      if (d[e.v] == d[e.u] + 1) {
        long long amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (long long pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  long long MaxFlow(int S, int T) {
    long long total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (long long flow = DFS(S, T)) total += flow;
    }
    return total;
  }
};
vector<long long> Dijkstra(const vector<list<pair<int, long long>>> &g, int s) {
  vector<long long> d(int((g).size()), numeric_limits<long long>::max() / 2LL);
  priority_queue<pair<long long, int>> q;
  d[s] = 0;
  q.emplace(-0, s);
  while (!q.empty()) {
    while (q.top().first > d[q.top().second]) {
      q.pop();
    }
    int v = q.top().second;
    q.pop();
    for (const auto &cw : g[v]) {
      if (d[v] + cw.second < d[cw.first]) {
        d[cw.first] = d[v] + cw.second;
        q.emplace(-d[cw.first], cw.first);
      }
    }
  }
  return d;
}
struct BinarySearchIterator
    : public std::iterator<std::forward_iterator_tag, bool> {
  long long value;
  typename iterator_traits<BinarySearchIterator>::difference_type operator-(
      const BinarySearchIterator &it) const {
    return value - it.value;
  }
  BinarySearchIterator &operator++() {
    ++value;
    return *this;
  }
  bool operator!=(const BinarySearchIterator &it) const {
    return value != it.value;
  }
  bool operator*() const { return true; }
};
template <int ALPHA>
class AhoCorasick {
 public:
  static const int ILLEGAL_INDEX;
  static const int ROOT;
  struct Node {
    bool leaf;
    int parent;
    int parentCharacter;
    int link;
    int next[ALPHA];
    int go[ALPHA];
    int outputFunction;
    Node(int parent = ILLEGAL_INDEX, int parentCharacter = ALPHA)
        : leaf(false),
          parent(parent),
          parentCharacter(parentCharacter),
          link(ILLEGAL_INDEX),
          outputFunction(ILLEGAL_INDEX) {
      fill_n(next, ALPHA, ILLEGAL_INDEX);
      fill_n(go, ALPHA, ILLEGAL_INDEX);
    }
  };
  vector<Node> tree = vector<Node>(1);
  AhoCorasick() {}
  AhoCorasick(int maxStatesNumber) { tree.reserve(maxStatesNumber); }
  template <class Iterator>
  void add(int length, const Iterator begin) {
    int vertex = ROOT;
    for (int i = 0; i < length; ++i) {
      if (ILLEGAL_INDEX == tree[vertex].next[begin[i]]) {
        tree[vertex].next[begin[i]] = int((tree).size());
        tree.push_back(Node(vertex, begin[i]));
      }
      vertex = tree[vertex].next[begin[i]];
    }
    tree[vertex].leaf = true;
  }
  int getLink(int vertex) {
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].link) {
      if (ROOT == vertex || ROOT == tree[vertex].parent) {
        tree[vertex].link = ROOT;
      } else {
        tree[vertex].link =
            go(getLink(tree[vertex].parent), tree[vertex].parentCharacter);
      }
    }
    return tree[vertex].link;
  }
  int go(int vertex, int character) {
    assert(0 <= character && character < ALPHA);
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].go[character]) {
      if (ILLEGAL_INDEX == tree[vertex].next[character]) {
        tree[vertex].go[character] =
            ROOT == vertex ? ROOT : go(getLink(vertex), character);
      } else {
        tree[vertex].go[character] = tree[vertex].next[character];
      }
    }
    return tree[vertex].go[character];
  }
  int getOutputFunction(int vertex) {
    assert(0 <= vertex && vertex < tree.size());
    if (ILLEGAL_INDEX == tree[vertex].outputFunction) {
      if (tree[vertex].leaf || ROOT == vertex) {
        tree[vertex].outputFunction = vertex;
      } else {
        tree[vertex].outputFunction = getOutputFunction(getLink(vertex));
      }
    }
    return tree[vertex].outputFunction;
  }
};
template <int ALPHA>
const int AhoCorasick<ALPHA>::ILLEGAL_INDEX = -1;
template <int ALPHA>
const int AhoCorasick<ALPHA>::ROOT = 0;
vector<list<int>> g;
vector<int> is_max;
pair<int, int> dfs(int vertex) {
  int total = 0;
  int min_after = int((g).size()) + 1;
  int total_before = 0;
  for (int child : g[vertex]) {
    auto index_size = dfs(child);
    min_after = min(index_size.second - index_size.first, min_after);
    total_before += index_size.first;
    total += index_size.second;
  }
  int index;
  if (g[vertex].empty()) {
    index = 0;
    total = 1;
  } else if (is_max[vertex]) {
    index = total - min_after;
  } else {
    index = total_before;
  }
  assert(0 <= index);
  assert(index < total);
  return make_pair((index), (total));
}
void build_graph(const vector<int> &f) {
  const int n = int((f).size()) + 1;
  g.assign(n, list<int>());
  for (int i = (1); i < (n); ++i) {
    g[f[i - 1]].push_back(i);
  }
}
int solve(const vector<int> &f) {
  build_graph(f);
  auto index_size = dfs(0);
  return index_size.first;
}
vector<int> generate() {
  int n = 2 + rand() % 8;
  vector<int> f(n - 1);
  for (int i = (0); i < (n - 1); ++i) {
    f[i] = rand() % (i + 1);
  }
  is_max.resize(n);
  for (int i = (0); i < (n); ++i) {
    is_max[i] = rand() % 2;
  }
  return f;
}
int dfs(int vertex, const vector<int> &order, int &index) {
  if (g[vertex].empty()) {
    return order[index++];
  }
  int answer = is_max[vertex] ? -1 : int((order).size());
  for (int child : g[vertex]) {
    int current = dfs(child, order, index);
    if (is_max[vertex]) {
      answer = max(answer, current);
    } else {
      answer = min(answer, current);
    }
  }
  return answer;
}
int bf(const vector<int> &f) {
  int n = int((f).size()) + 1;
  build_graph(f);
  vector<int> leaves;
  for (int i = (0); i < (n); ++i) {
    if (g[i].empty()) {
      leaves.push_back((i));
    }
  }
  vector<int> order(int((leaves).size()));
  for (int i = (0); i < (int((order).size())); ++i) {
    order[i] = i;
  }
  int answer = -1;
  do {
    int index = 0;
    int current = dfs(0, order, index);
    assert(index == int((order).size()));
    if (current > answer) {
      answer = current;
    }
  } while (next_permutation((order).begin(), (order).end()));
  return answer;
}
void stress() {
  is_max = {1, 0, 1, 1, 0, 1};
  assert(0 == solve({0, 1, 1, 1, 1}));
  {
    is_max = {0, 1, 1, 1, 1, 0, 0};
    auto a = solve({0, 1, 1, 0, 4, 4});
    assert(2 == a);
  }
  is_max = {1, 0, 1, 0, 1};
  assert(3 == bf({0, 0, 0, 0}));
  assert(3 == solve({0, 0, 0, 0}));
  is_max = {1, 0, 0, 1, 0, 1, 1, 0};
  assert(3 == bf({0, 0, 1, 1, 2, 2, 2}));
  assert(3 == solve({0, 0, 1, 1, 2, 2, 2}));
  is_max = {1, 1, 0, 0, 1, 0, 1, 0, 1};
  assert(4 == bf({0, 0, 1, 1, 2, 2, 3, 3}));
  assert(4 == solve({0, 0, 1, 1, 2, 2, 3, 3}));
  while (true) {
    auto f = generate();
    auto o = solve(f);
    auto a = bf(f);
    assert(a == o);
    cerr << "OK" << endl;
  }
}
int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  srand((unsigned int)time(NULL));
  int n;
  while (cin >> n) {
    is_max.resize(n);
    for (int i = (0); i < (n); ++i) {
      cin >> is_max[i];
    }
    vector<int> f(n - 1);
    for (int i = (1); i < (n); ++i) {
      cin >> f[i - 1];
      --f[i - 1];
    }
    cout << 1 + solve(f) << endl;
  }
  return 0;
}

```