#include <iostream>
#define ll long long
#include <algorithm>
#include <queue>
using namespace std;

int n;
int *a, *b;
priority_queue<pair<int,int> > v;
pair<int,int> *pov;
int kor, sz = 0, las;
priority_queue<int> izb;
ll res = 0;
bool *prm;
/*bool mesto(int j, int i)
{
    if(i > j && (pov[i].first > i || pov[i].first == 0)) return 1;
    if(i < j) return 1;
    return 0;
}
void stampajpov(int kor)
{
    for(; kor != 0; kor = pov[kor].first) cout << kor << " ";
    //cout << "stp\n";
}*/
ll m = LLONG_MAX;
void radi(int N)
{
	
	sz = 0;
	res = 0;
	for(int i = 0; i < 2 * N; i++)
	{
		
		bool prov = 0;
		for(int j = 0; j < N && !prov; j++)
		{
			if(a[j] == i)
			{
				prov = 1;
				if(sz == 0)
				{
					kor = j;
					las = j;
				}
				else
				{
					if(prm[j])
					{
						pov[j].first = kor;
						pov[kor].second = j;
						kor = j;
					}
					else
					{
						pov[las].first = j;
						pov[j].second = las;
						las = j;
					}
				}
			}
		}
		for(int j = 0; j < N && !prov; j++)
		{
			if(b[j] == i)
			{
			
				prov = 1;
				for(int k = kor; k != j; k = pov[k].first, res++)
				{
						cout << "L ";
				}
			}
		}
	}
	if(res < m) m = res;
}
void perm(int i, int N)
{
	if(i == N) radi(N);
	prm[i] = 1;
	perm(i+1, N);
	prm[i] = 0;
	perm(i+1, N);
}
long long Resi(int N, int *A, int *B)
{
	a = A;
	b = B;
	prm = new bool[N];
    perm(0, N);
    return m;
}
int main() {
	/*ios_base::sync_with_stdio(false);
	cin.tie(nullptr);*/

    int N;
    cin >> N;

    int *A = new int[N], *B = new int[N];
    for(int i = 0; i < N; i++)
        cin >> A[i] >> B[i];

    long long res = Resi(N, A, B);
    cout << res << endl;

    delete[] A;
    delete[] B;

    return 0;
}