import java.util.Scanner;

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

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int m = scanner.nextInt(); m scanner.nextInt() scanner.nextInt scanner int left = Integer.MIN_VALUE; left Integer.MIN_VALUE Integer Integer.MIN_VALUE int right = Integer.MAX_VALUE; right Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        } {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        } left = Math.max(left, scanner.nextInt()) left Math.max(left, scanner.nextInt()) Math.max Math left scanner.nextInt() scanner.nextInt scanner right = Math.min(right, scanner.nextInt()) right Math.min(right, scanner.nextInt()) Math.min Math right scanner.nextInt() scanner.nextInt scanner System.out.println(Math.max(0, (right - left) + 1)) System.out.println System.out System System.out Math.max(0, (right - left) + 1) Math.max Math 0 (right - left) + 1 (right - left) right left 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
} Main
import java.util.Scanner;

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

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
}