import java.util.BitSet;
import java.util.Scanner;

class Solver {
    Solver(Scanner in){
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    }

    void solve() {

    }
}

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
} import java.util.BitSet; BitSet java.util import java.util.Scanner; Scanner java.util class Solver {
    Solver(Scanner in){
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    }

    void solve() {

    }
} Solver Solver(Scanner in){
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    } Solver {
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    } int N = in.nextInt(); N in.nextInt() in.nextInt in int M = in.nextInt(); M in.nextInt() in.nextInt in BitSet bits = new BitSet(N); bits new BitSet(N) bits.set(0, N) bits.set bits 0 N for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        } {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        } BitSet gate = new BitSet(N); gate new BitSet(N) gate.set(in.nextInt() - 1, in.nextInt()) gate.set gate in.nextInt() - 1 in.nextInt() in.nextInt in 1 in.nextInt() in.nextInt in bits.and(gate) bits.and bits gate System.out.println(bits.cardinality()) System.out.println System.out System System.out bits.cardinality() bits.cardinality bits Scanner in in void solve() {

    } solve {

    } class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
} Main public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    } main {
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) new Solver(in).solve() new Solver(in).solve new Solver(in) in.close() in.close in String[] args args
import java.util.BitSet;
import java.util.Scanner;

class Solver {
    Solver(Scanner in){
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    }

    void solve() {

    }
}

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
}