#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
using namespace std;

int main() {
	int N; cin >> N;

	vector <int> P(N);
	vector <int> Q(N);
	int p = 0, q = 0;

	for (int i = 0; i < N; i++) {
		cin >> P.at(i);
		p += P.at(i) * pow(10, N - i - 1);
	}
	for (int i = 0; i < N; i++) {
		cin >> Q.at(i);
		q += Q.at(i) * pow(10, N - i - 1);
	}
	
	int cnt = 0;
	int Pcnt = 0;
	int Qcnt = 0;
	for (int a = 1; a <= N; a++) {
		for (int b = 1; b <= N && N >= 2; b++) {
			if (N == 2) {
				if (a != b) {
					cnt++;
					if (p == a * 10 + b) {
						Pcnt = cnt;
					}
					if (q == a * 10 + b) {
						Qcnt = cnt;
					}
				}
			}
			for (int c = 1; c <= N && N >= 3; c++) {
				if (N == 3) {
					if (a != b && b != c && a != c) {
						cnt++;
						if (p == a * 100 + b * 10 + c) {
							Pcnt = cnt;
						}
						if (q == a * 100 + b * 10 + c) {
							Qcnt = cnt;
						}
					}
				}
				for (int d = 1; d <= N && N >= 4; d++) {
					if (N == 4) {
						if (a != b && a != c && a != d && b != c && b != d && c != d) {
							cnt++;
							if (p == a * 1000 + b * 100 + c * 10 + d) {
								Pcnt = cnt;
							}
							if (q == a * 1000 + b * 100 + c * 10 + d) {
								Qcnt = cnt;
							}
						}
					}
					for (int e = 1; e <= N && N >= 5; e++) {
						if (N == 5) {
							if (a != b && a != c && a != d && a != e && b != c && b != d  && b != e && c != d && c != e && d != e) {
								cnt++;
								if (p == a * 10000 + b * 1000 + c * 100 + d * 10 + e) {
									Pcnt = cnt;
								}
								if (q == a * 10000 + b * 1000 + c * 100 + d * 10 + e) {
									Qcnt = cnt;
								}
							}
						}
						for (int f = 1; f <= N && N >= 6; f++) {
							if (N == 6) {
								if (a != b && a != c && a != d && a != e && a != f && b != c && b != d && b != e && b != f && c != d && c != e && c != f && d != e && d != f && e != f) {
									cnt++;
									if (p == a * 100000 + b * 10000 + c * 1000 + d * 100 + e * 10 + f) {
										Pcnt = cnt;
									}
									if (q == a * 100000 + b * 10000 + c * 1000 + d * 100 + e * 10 + f) {
										Qcnt = cnt;
									}
								}
							}
							for (int g = 1; g <= N && N >= 7; g++) {
								if (N == 7) {
									if (a != b && a != c && a != d && a != e && a != f && a != g && b != c && b != d && b != e && b != f && b != g && c != d && c != e && c != f && c != g && d != e && d != f && d != g && e != f && e != g && f != g) {
										cnt++;
										if (p == a * 1000000 + b * 100000 + c * 10000 + d * 1000 + e * 100 + f * 10 + g) {
											Pcnt = cnt;
										}
										if (q == a * 1000000 + b * 100000 + c * 10000 + d * 1000 + e * 100 + f * 10 + g) {
											Qcnt = cnt;
										}
									}
								}
								for (int h = 1; h <= N && N >= 8; h++) {
									if (N == 8) {
										if (a != b && a != c && a != d && a != e && a != f && a != g && a != h && b != c && b != d && b != e && b != f && b != g && b != h && c != d && c != e && c != f && c != g && c != h && d != e && d != f && d != g && d != h && e != f && e != g && e != h && f != g && f != h && g != h) {
											cnt++;
											if (p == a * 10000000 + b * 1000000 + c * 100000 + d * 10000 + e * 1000 + f * 100 + g * 10 + h) {
												Pcnt = cnt;
											}
											if (q == a * 10000000 + b * 1000000 + c * 100000 + d * 10000 + e * 1000 + f * 100 + g * 10 + h) {
												Qcnt = cnt;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	

	cout << abs(Pcnt - Qcnt) << endl;

	return 0;
}

Measured memory_bytes: 384