#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	vector<int> dat;
	vector<int> gg;
	vector<int> inf;
	scanf("%d",&n);
	int i;
	int x;
	gg.push_back(1);
	for(i = 1; i <= n; i++){
		dat.push_back(i);
		gg.push_back(gg[i-1]*10);
	}
	inf.reserve(50000);
	do {
		x = 0;
        for(i = 0; i < n; i++)
        	x += dat[i]*gg[i];
        inf.push_back(x);
        //for(i = 0; i < n; i++) printf("%d, ",dat[i]); printf("__ %d\n",x);
    } while(next_permutation(dat.begin(), dat.end()));
	int a = 0,b = 0;
	vector<int> va(n),vb(n);
	for (i = 0; i < n; ++i)
		scanf("%d",&va[i]);
	for (i = 0; i < n; ++i)
		scanf("%d",&vb[i]);
	
	for(i = 0; i < n; i++){
        a += va[i]*gg[i];
        b += vb[i]*gg[i];
	}
	int A=0,B=0;
	n = inf.size();
	for(i = 0; i < n; i++){
		if(a == inf[i])
			A = i;
		if(b == inf[i])
			B = i;
	}
	//printf("%d %d, a=%d, b=%d\n",A,B,a,b);
	//for(i = 0; i < gg.size(); i++)
	//	printf("%d, ", gg[i]);
	//printf("\n");
	printf("%d\n",abs(A-B));
	return 0;
}