import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto p = readln.chomp.split.to!(int[]);
  auto q = readln.chomp.split.to!(int[]);

  int[][] ar;
  auto f = new int[](n);
  f[] = false;
  void calc(int[] a) {
    if (a.length == n) {
      ar ~= a;
      return;
    }

    foreach (i; 0..n) {
      if (f[i]) continue;
      f[i] = true;
      calc(a ~ (i + 1));
      f[i] = false;
    }
  }

  int[] tmp;
  calc(tmp);
  int pr, qr;
  foreach (i; 0..ar.length) {
    if (p == ar[i]) {
      pr = i + 1;
    }
    if (q == ar[i]) {
      qr = i + 1;
    }
  }
  abs(pr - qr).writeln;
}
