import java.util.*;

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

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int LMax = 0; LMax 0 int RMin = N; RMin N for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        } {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc LMax = L >= LMax ? L : LMax LMax L >= LMax ? L : LMax L >= LMax L LMax L LMax RMin = R <= RMin ? R : RMin RMin R <= RMin ? R : RMin R <= RMin R RMin R RMin sc.close() sc.close sc if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        } LMax > RMin LMax RMin {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(RMin - LMax + 1);
        } System.out.println(RMin - LMax + 1) System.out.println System.out System System.out RMin - LMax + 1 RMin - LMax RMin LMax 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

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

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    }
} Main
import java.util.*;

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

        int LMax = 0;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            LMax = L >= LMax ? L : LMax;
            RMin = R <= RMin ? R : RMin;
        }
        sc.close();

        if (LMax > RMin) {
            System.out.println(0);
        } else {
            System.out.println(RMin - LMax + 1);
        }

    }
}
