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 max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+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 max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+1);
        }

    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+1);
        }

    } main {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+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 max = N; max N int min = Integer.MIN_VALUE; min Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } int l = scanner.nextInt(); l scanner.nextInt() scanner.nextInt scanner int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner min = Math.max(min, l) min Math.max(min, l) Math.max Math min l max = Math.min(max, r) max Math.min(max, r) Math.min Math max r if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+1);
        } max < min max min {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(max-min+1);
        } System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 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 max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+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 max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+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 max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+1);
        }

    }
}
