import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
} Main static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768); br new BufferedReader(new InputStreamReader(System.in), 32768) static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) static StringTokenizer t; t static long mod = 998244353; mod 998244353 static long maxn = 200005; maxn 200005 static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    } sn {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    } while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } t == null || !t.hasMoreTokens() t == null t null !t.hasMoreTokens() t.hasMoreTokens() t.hasMoreTokens t {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            } catch (IOException e) {
                throw new RuntimeException();
            } IOException e {
                throw new RuntimeException();
            } throw new RuntimeException(); new RuntimeException() {
                t = new StringTokenizer(br.readLine());
            } t = new StringTokenizer(br.readLine()) t new StringTokenizer(br.readLine()) return t.nextToken(); t.nextToken() t.nextToken t static int ni() {
        return Integer.parseInt(sn());
    } ni {
        return Integer.parseInt(sn());
    } return Integer.parseInt(sn()); Integer.parseInt(sn()) Integer.parseInt Integer sn() sn static long nlo() {
        return Long.parseLong(sn());
    } nlo {
        return Long.parseLong(sn());
    } return Long.parseLong(sn()); Long.parseLong(sn()) Long.parseLong Long sn() sn public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    } main {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    } int t = 1; t 1 while (t-- > 0) {
            solve();
        } t-- > 0 t-- t 0 {
            solve();
        } solve() solve out.close() out.close out String args[] args static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    } pro {
        return (a % mod * b % mod) % mod;
    } return (a % mod * b % mod) % mod; (a % mod * b % mod) % mod (a % mod * b % mod) a % mod * b a % mod a mod b mod mod long a a long b b static long add(long a, long b) {
        return (a + b) % mod;
    } add {
        return (a + b) % mod;
    } return (a + b) % mod; (a + b) % mod (a + b) a b mod long a a long b b static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    } solve {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    } int n = ni(); n ni() ni int m = ni(); m ni() ni int dp[] = new int[n + 1]; dp new int[n + 1] n + 1 n 1 for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        } {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        } int l = ni() - 1; l ni() - 1 ni() ni 1 int r = ni() - 1; r ni() - 1 ni() ni 1 dp[l]++ dp[l] dp l dp[r + 1] -= 1 dp[r + 1] dp r + 1 r 1 1 int ans = 0; ans 0 if (dp[0] == m)
            ans += 1; dp[0] == m dp[0] dp 0 m ans += 1 ans 1 for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        } int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        } {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        } dp[i] += dp[i - 1] dp[i] dp i dp[i - 1] dp i - 1 i 1 if (dp[i] == m)
                ans++; dp[i] == m dp[i] dp i m ans++ ans out.println(ans) out.println out ans public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
} public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
}