// Arup Guha
// 3/26/2015
// Solution to 2013 USACO December Bronze Problem: Wormholes

import java.util.*;
import java.io.*;

public class wormhole {

	public static int n;
	public static pt[] myPts;
	public static int result;
	public static int[] next;

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("wormhole.in"));
		n = stdin.nextInt();

		// Store cows.
		myPts = new pt[n];
		for (int i=0; i<n; i++) {
			int x = stdin.nextInt();
			int y = stdin.nextInt();
			myPts[i] = new pt(x, y);
		}
		stdin.close();

		// Figuring out where we go, when we go right, the slow way.
		next = new int[n];
		Arrays.fill(next, -1);

		// Try moving in the +x direction from each pt.
		for (int i=0; i<n; i++)	{

			int res = -1;
			for (int j=0; j<n; j++) {

				// Can't be the same point or different y value...
				if (i == j || myPts[i].y != myPts[j].y) continue;

				// Can't be to the left..
				if (myPts[j].x < myPts[i].x) continue;

				// This is the condition to update.
				if (res == -1 || myPts[j].x < myPts[res].x)
					res = j;
			}

			// Set it.
			next[i] = res;
		}

		// Solve and write out the result.
		FileWriter fout = new FileWriter(new File("wormhole.out"));
		fout.write(solve()+"\n");
		fout.close();
	}

	// Wrapper function.
	public static int solve() {
		int[] perm = new int[n];
		boolean[] used = new boolean[n];
		return go(perm, used, 0);
	}

	public static int go(int[] perm, boolean[] used, int k) {

		// Finished a pairing - evaluate it.
		if (k == n) return eval(perm);

		// Only one item to place in this spot.
		if (k%2 == 0) {
			int loc = 0;
			while (used[loc]) loc++;
			perm[k] = loc;
			used[loc] = true;
			int res = go(perm, used, k+1);
			used[loc] = false;
			return res;
		}

		// Try all possible items here.
		else {

			int res = 0;

			// By definition, each item in this slot must be greater than the previous...
			for (int i=perm[k-1]+1; i<n; i++) {
				if (!used[i]) {
					perm[k] = i;
					used[i] = true;
					res += go(perm, used, k+1);
					used[i] = false;
				}
			}

			// Final answer...
			return res;
		}
	}

	public static int eval(int[] perm) {

		// Just store where this permutation forwards you...
		int[] portal = new int[n];
		for (int i=0; i<n; i+=2) {
			portal[perm[i]] = perm[i+1];
			portal[perm[i+1]] = perm[i];
		}

		// Start represents where we start our journey, walking right...
		for (int start=0; start<n; start++) {

			// Initialize stuff...
			int cur = start;

			// Just try this process for long enough (more than n)
			for (int step=0; step<2*n+1; step++) {

				// Use the portal then walk.
				cur = portal[cur];
				cur = next[cur];

				// No cycle.
				if (cur == -1) break;
			}

			// Means we must have hit a cycle.
			if (cur != -1) return 1;
		}

		// If we get here, we never found a cycle.
		return 0;
	}
}

class pt {

	public int x;
	public int y;

	public pt(int myx, int myy) {
		x = myx;
		y = myy;
	}
}