import java.util.Arrays;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int l=0;
        int max=0;
        int m=sc.nextInt();
        int[][]arr=new int[m][2];
        for (int i = 0; i < m; i++) {
           arr[i][0]=sc.nextInt();
           arr[i][1]=sc.nextInt();
        }
        Arrays.sort(arr,(a,b)->Integer.compare(a[0], b[0]));
        for (int i = 0; i < arr.length; i++) {
            int from=arr[i][0];
            int to=arr[i][1];
            if(from>l){
                int duration=from-l-1;
                max=Math.max(max, duration);
            }
            l=Math.max(l, to);
        }
        max=Math.max(max, n-l);
        System.out.println(max);
        sc.close();
    }

}