import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Solution to ICPC Team Generation
 * 
 * @author vanb
 */
public class icpc_greedy_vanb
{
    /** Input. */
    private static Scanner sc;
    
    /** Output. */
    private static PrintStream ps;
    
    private int a[], b[];
    
    private boolean compatible( int i, int j )
    {
        return a[i] <= j && j <= b[i] && a[j] <= i && i <= b[j];
    }
    
    /**
     * Do it!
     */
    private void doit()
    {
        int n = sc.nextInt();
        a = new int[n];
        b = new int[n];
        for( int i=0; i<n; i++ )
        {
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
        }
        
        int answer = 0;
        for( int i=0; i<n-2; i++ )
        {
            if( compatible(i,i+1) && compatible(i,i+2) && compatible(i+1,i+2) )
            {
                ++answer;
                i += 2;
            }
        }
        
        ps.println( answer );
    }
        
    /**
     * Main.
     * 
     * @param args unused
     * @throws Exception
     */
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new icpc_greedy_vanb().doit();
    }

}
