import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        Out out = new Out();
        solve(out);
        out.outln();
        out.flush();
        out.close();
    }

    public static void solve(Out out) {
        int n = In.ni();
        int m = In.ni();
        int[] g = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = In.ni() - 1;
            int r = In.ni() - 1;
            g[l]++;
            g[r + 1]--;
        }
        int[] s = CumulativeSum.build(g);
        int a = 0;
        for (int i = 1; i <= n; i++) {
            if (s[i] == m) {
                a++;
            }
        }
        out.append(a);
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

class CumulativeSum {
    /**
     * s[i] is the sum of {a[x] | 0 <= x < i}.
     * @param a
     * @return cumulative sum array of a.
     */
    public static int[] build(int[] a) {
        int n = a.length;
        int[] s = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            s[i] = s[i - 1] + a[i - 1];
        }
        return s;
    }
    
    /**
     * s[i][j] is the sum of {a[x][y] | 0 <= x < i and 0 <= y < j}.
     * @param a
     * @return
     */
    public static int[][] build(int[][] a) {
        int n = a.length;
        int m = a[0].length;
        int[][] s = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++){
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i - 1][j - 1];
            }
        }
        return s;
    }

    /**
     * s[i] is the sum of {a[x] | 0 <= x < i}.
     * @param a
     * @return cumulative sum array of a.
     */
    public static long[] build(long[] a) {
        int n = a.length;
        long[] s = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            s[i] = s[i - 1] + a[i - 1];
        }
        return s;
    }

    /**
     * s[i][j] is the sum of {a[x][y] | 0 <= x < i and 0 <= y < j}.
     * @param a
     * @return
     */
    public static long[][] build(long[][] a) {
        int n = a.length;
        int m = a[0].length;
        long[][] s = new long[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i - 1][j - 1];
            }
        }
        return s;
    }

    public static int sum(int[] s, int l, int r) {
        return s[r] - s[l];
    }

    public static long sum(long[] s, int l, int r) {
        return s[r] - s[l];
    }

    public static int sum(int[][] s, int l1, int r1, int l2, int r2) {
        return s[l2][r2] - s[l1][r2] - s[l2][r1] + s[l1][r1];
    }

    public static long sum(long[][] s, int l1, int r1, int l2, int r2) {
        return s[l2][r2] - s[l1][r2] - s[l2][r1] + s[l1][r1];
    }
}


class Out {
    private StringBuilder sb = new StringBuilder();
    private PrintWriter w = new PrintWriter(System.out);

    public Out() {
    }

    public void append(int v) {
        sb.append(v);
    }

    public void append(int[] a, String sep) {
        for (int i = 0; i < a.length; i++) {
            append(a[i]);
            if (i < a.length - 1) {
                append(sep);
            }
        }
    }

    public void append(int[] a, char sep) {
        append(a, String.valueOf(sep));
    }

    public void append(int[] a) {
        append(a, "\n");
    }

    public void append(long v) {
        sb.append(v);
    }

    public void append(long[] a, String sep) {
        for (int i = 0; i < a.length; i++) {
            append(a[i]);
            if (i < a.length - 1) {
                append(sep);
            }
        }
    }

    public void append(long[] a, char sep) {
        append(a, String.valueOf(sep));
    }

    public void append(long[] a) {
        append(a, "\n");
    }

    public void append(double v) {
        sb.append(v);
    }

    public void append(double[] a, String sep) {
        for (int i = 0; i < a.length; i++) {
            append(a[i]);
            if (i < a.length - 1) {
                append(sep);
            }
        }
    }

    public void append(double[] a, char sep) {
        append(a, String.valueOf(sep));
    }

    public void append(double[] a) {
        append(a, "\n");
    }

    public void append(char c) {
        sb.append(c);
    }

    public void append(char[] c) {
        sb.append(c);
    }

    public void append(char[][] c) {
        for (char[] e : c) {
            append(e);
            append('\n');
        }
    }

    public void append(String[] a, String sep) {
        for (int i = 0; i < a.length; i++) {
            append(a[i]);
            if (i < a.length - 1) {
                append(sep);
            }
        }
    }

    public void append(String[] a, char sep) {
        append(a, String.valueOf(sep));
    }

    public void append(String[] a) {
        append(a, "\n");
    }

    public void append(Object e) {
        sb.append(e);
    }

    public void append(Object[] a, String sep) {
        for (int i = 0; i < a.length; i++) {
            append(a[i]);
            if (i < a.length - 1) {
                append(sep);
            }
        }
    }

    public void append(Object[] a, char sep) {
        append(a, String.valueOf(sep));
    }

    public void append(Object[] a) {
        append(a, "\n");
    }

    public void out() {
        w.print(sb);
        clearBuilder();
    }

    public void outln() {
        w.println(sb);
        clearBuilder();
    }

    // public void print(String s) {
    //     w.print(s);
    // }

    // public void println() {
    //     w.println();
    // }

    // public void println(int v) {
    //     w.println(v);
    // }

    // public void println(long v) {
    //     w.println(v);
    // }

    // public void println(double v) {
    //     w.println(v);
    // }

    // public void println(char c) {
    //     w.println(c);
    // }

    // public void println(String s) {
    //     w.println(s);
    // }

    // public void println(Object e) {
    //     w.println(e);
    // }

    // public void println(String sep, int... a) {
    //     StringBuilder s = new StringBuilder();
    //     for (int i = 0; i < a.length; i++) {
    //         s.append(a[i]);
    //         if (i < a.length - 1) {
    //             s.append(sep);
    //         }
    //     }
    //     println(s.toString());
    // }

    // public void println(char sep, int... a) {
    //     println(String.valueOf(sep), a);
    // }

    // public void println(String sep, long... a) {
    //     StringBuilder s = new StringBuilder();
    //     for (int i = 0; i < a.length; i++) {
    //         s.append(a[i]);
    //         if (i < a.length - 1) {
    //             s.append(sep);
    //         }
    //     }
    //     println(s.toString());
    // }

    // public void println(char sep, long... a) {
    //     println(String.valueOf(sep), a);
    // }

    // public void println(String sep, double... a) {
    //     StringBuilder s = new StringBuilder();
    //     for (int i = 0; i < a.length; i++) {
    //         s.append(a[i]);
    //         if (i < a.length - 1) {
    //             s.append(sep);
    //         }
    //     }
    //     println(s.toString());
    // }

    // public void println(char sep, double... a) {
    //     println(String.valueOf(sep), a);
    // }

    // public void println(String sep, String... a) {
    //     StringBuilder s = new StringBuilder();
    //     for (int i = 0; i < a.length; i++) {
    //         s.append(a[i]);
    //         if (i < a.length - 1) {
    //             s.append(sep);
    //         }
    //     }
    //     println(s.toString());
    // }

    // public void println(char sep, String... a) {
    //     println(String.valueOf(sep), a);
    // }

    // public void println(String sep, Object... a) {
    //     StringBuilder s = new StringBuilder();
    //     for (int i = 0; i < a.length; i++) {
    //         s.append(a[i]);
    //         if (i < a.length - 1) {
    //             s.append(sep);
    //         }
    //     }
    //     println(s.toString());
    // }

    // public void println(char sep, Object... a) {
    //     println(String.valueOf(sep), a);
    // }

    public void flush() {
        w.flush();
    }

    public void close() {
        w.close();
    }

    public void clearBuilder() {
        sb = new StringBuilder();
    }

    public void reverse() {
        sb.reverse();
    }

    public void delete(int start, int end) {
        sb.delete(start, end);
    }

    public void delete(int length) {
        sb.delete(sb.length() - length, sb.length());
    }

    public int length() {
        return sb.length();
    }
}


class In {
    public static final FastScanner fsc = new FastScanner();

    public static int ni() {
        return fsc.nextInt();
    }

    public static int[] ni(int n) {
        int[] a = new int[n];
        Arrays.setAll(a, i -> fsc.nextInt());
        return a;
    }

    public static int[][] ni(int n, int m) {
        int[][] a = new int[n][m];
        Arrays.setAll(a, i -> ni(m));
        return a;
    }

    public static long nl() {
        return fsc.nextLong();
    }

    public static long[] nl(int n) {
        long[] a = new long[n];
        Arrays.setAll(a, i -> fsc.nextLong());
        return a;
    }

    public static long[][] nl(int n, int m) {
        long[][] a = new long[n][m];
        Arrays.setAll(a, i -> nl(m));
        return a;
    }

    public static double nd() {
        return fsc.nextDouble();
    }

    public static double[] nd(int n) {
        double[] a = new double[n];
        Arrays.setAll(a, i -> nd());
        return a;
    }

    public static double[][] nd(int n, int m) {
        double[][] a = new double[n][m];
        Arrays.setAll(a, i -> nd(m));
        return a;
    }

    public static String ns() {
        return fsc.next();
    }

    public static String[] ns(int n) {
        String[] s = new String[n];
        Arrays.setAll(s, i -> ns());
        return s;
    }

    public static char[] nc() {
        return fsc.next().toCharArray();
    }

    public static char[][] nc(int n, int m) {
        char[][] c = new char[n][m];
        Arrays.setAll(c, i -> nc());
        return c;
    }

    public static boolean[][] inputGrid(int h, int w, char truechar) {
        boolean[][] grid = new boolean[h][w];
        for (int i = 0; i < h; i++) {
            char[] s = fsc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                grid[i][j] = s[j] == truechar;
            }
        }
        return grid;
    }
}


Measured memory_bytes: 23112