import 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();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    } main {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    } 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 boolean[] cards = new boolean[n]; cards new boolean[n] n int l l r; r for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	} int i=0; int i=0; i 0 i<m i m i++ i++ i {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	} {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	} l = sc.nextInt()-1 l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 r = sc.nextInt()-1 r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 for (int j=0; j<l; j++) cards[j] = true; int j=0; int j=0; j 0 j<l j l j++ j++ j cards[j] = true; cards[j] = true cards[j] cards j true for (int j=r+1; j<n; j++) cards[j] = true; int j=r+1; int j=r+1; j r+1 r 1 j<n j n j++ j++ j cards[j] = true; cards[j] = true cards[j] cards j true int count = 0; count 0 for (int i=0; i<n; i++)
	    if (cards[i] == false) count++; int i=0; int i=0; i 0 i<n i n i++ i++ i if (cards[i] == false) count++; if (cards[i] == false) count++; cards[i] == false cards[i] cards i false count++ count System.out.print(count) System.out.print System.out System System.out count 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();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
} public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
} Main
import 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();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
}
