#include <bits/stdc++.h>
using namespace std;

bool in[1000005], in2[1000005];
int min_pos[1000005];

int main() {
  ifstream IN("input");
  ifstream USR("user_out");

  int n;
  IN >> n;
  vector<int> a(n+1), b(n+5), c;

  bool fl = 1, _1 = 0;
  for(int i = 1; i <= n; ++i) {
    IN >> a[i];
    in[a[i]] = 1;
    if(!min_pos[a[i]]) min_pos[a[i]] = i;
  }
  for(int i = 1; i <= n; ++i) {
    fl &= in[i];
    if(!fl && in[i]) {_1 = 1; break;}
    if(i > 1 && min_pos[i] < min_pos[i-1] && min_pos[i] > 0 && min_pos[i-1] > 0) {
      _1 = 1; break;
    }
  }
  // valid input
  int len = 1;
  while((USR>>b[len])) {
    if(len > n) {
      cerr << "Wrong : Output limit exceeded."  << endl;
      puts("0");
      return 0;
    }
    len ++;
  }
  --len;
  if(len == 0) {
    cerr << "Wrong : No output."  << endl;
    puts("0");
    return 0;
  }
  if(_1) {
    if(len > 1 || b[1] != -1) {
      cerr << "Wrong : In the 1st column, expect -1, but get " << b[1] << endl;
      puts("0");
      return 0;
    }
    cerr << "Accepted." << endl;
    puts("100");
    return 0;
  }
  if(!_1) {
    if(len != n) {
      cerr << "Wrong : Not a permutaion." << endl;
      puts("0");
      return 0;
    }
    for(int i = 1; i <= n; ++i) {
      if(b[i] >= 1 && b[i] <= n) {
        in2[b[i]] = 1;
      }
    }
    for(int i = 1; i <= n; ++i) {
      if(!in2[i]) {
        cerr << "Wrong : Not a permutaion." << endl;
        puts("0");
        return 0;
      }
    }
  }

  for(int i = 1; i <= n; ++i) {
    int tmp;
    if(i == 1) {
      c.push_back(b[i]);
      tmp = 1;
    } else {
      if(lower_bound(c.begin(), c.end(), b[i]) == c.end()) {
        tmp = c.size() + 1;
        c.push_back(b[i]);
      } else {
        tmp = lower_bound(c.begin(), c.end(), b[i]) - c.begin() + 1;
        c[tmp - 1] = b[i];
      }
    }
    if(a[i] != tmp) {
      cerr << "Wrong : At position " << i << ", expect LIS = " << a[i] << ", but get " << tmp << "." << endl;
      puts("0");
      return 0;
    }
  }
  cerr << "Accepted." << endl;
  puts("100");
  return 0;
}