import java.util.*;

public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    }
} import java.util.*; util.* java public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    }
} Main private static final int INF = Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    } 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 l = 0; l 0 int r = INF; r INF for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        } int tmp = 0; int tmp = 0; tmp 0 tmp< m tmp m tmp++ tmp++ tmp {
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        } {
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        } int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc l = Math.max(x,l) l Math.max(x,l) Math.max Math x l int y = sc.nextInt(); y sc.nextInt() sc.nextInt sc r = Math.min(y,r) r Math.min(y,r) Math.min Math y r System.out.println(l <= r ? r - l + 1 : 0) System.out.println System.out System System.out l <= r ? r - l + 1 : 0 l <= r l r r - l + 1 r - l r l 1 0 String[] args args public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    }
} public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    }
} Main
import java.util.*;

public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int l = 0;
        int r = INF;
        for(int tmp = 0; tmp< m; tmp++){
            int x = sc.nextInt();
            l = Math.max(x,l);
            int y = sc.nextInt();
            r = Math.min(y,r);
        }

        System.out.println(l <= r ? r - l + 1 : 0);
    }
}
