import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner 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[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    } 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 = new int[m][2]; l new int[m][2] m 2 for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < 2 j 2 j++ j++ j {
                l[i][j] = sc.nextInt();
            } {
                l[i][j] = sc.nextInt();
            } l[i][j] = sc.nextInt() l[i][j] l[i] l i j sc.nextInt() sc.nextInt sc int[] nn = new int[n+1]; nn new int[n+1] n+1 n 1 for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        } {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        } int s = l[i][0]; s l[i][0] l[i] l i 0 int e = l[i][1]; e l[i][1] l[i] l i 1 for (int j = s; j < e + 1; j++) {
                nn[j]++;
            } int j = s; int j = s; j s j < e + 1 j e + 1 e 1 j++ j++ j {
                nn[j]++;
            } {
                nn[j]++;
            } nn[j]++ nn[j] nn j int ans = 0; ans 0 for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        } int i = 0; int i = 0; i 0 i < nn.length i nn.length nn nn.length i++ i++ i {
            if(nn[i] == m) ans++;
        } {
            if(nn[i] == m) ans++;
        } if(nn[i] == m) ans++; nn[i] == m nn[i] nn i m ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] l = new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                l[i][j] = sc.nextInt();
            }
        }
        int[] nn = new int[n+1];
        for (int i = 0; i < m; i++) {
            int s = l[i][0];
            int e = l[i][1];
            for (int j = s; j < e + 1; j++) {
                nn[j]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < nn.length; i++) {
            if(nn[i] == m) ans++;
        }
        System.out.println(ans);
    }
}