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

public class Main {

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);
    static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    }
}

class Reader {
 
    private final InputStream in;
    private final byte[] buf = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    public Reader() { this(System.in);}
    public Reader(InputStream source) { this.in = source;}
 
    private boolean hasNextByte() {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    }
 
    private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
 
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
 
    private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
 
    public boolean hasNext() {skip(); 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();
        boolean minus = false;
        long num = readByte();
 
        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
 
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    }
 
    public int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    }
 
    public String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();
 
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }
 
        return sb.toString();
    }
 
    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    }
 
    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    }
 
    public void close() {try{ in.close();}catch(IOException e){ e.printStackTrace();}};
} import java.util.*; util.* java import java.io.*; io.* java public class Main {

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);
    static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    }
} Main static final Reader sc = new Reader(); sc new Reader() static final PrintWriter out = new PrintWriter(System.out,false); out new PrintWriter(System.out,false) static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    } main {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    } int n = sc.nextInt() n sc.nextInt() sc.nextInt sc m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int l = 1 l 1 r = n; r n for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        } {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        } l = Math.max(l, sc.nextInt()) l Math.max(l, sc.nextInt()) Math.max Math l sc.nextInt() sc.nextInt sc r = Math.min(r, sc.nextInt()) r Math.min(r, sc.nextInt()) Math.min Math r sc.nextInt() sc.nextInt sc System.out.println(Math.max(0, r - l + 1)) System.out.println System.out System System.out Math.max(0, r - l + 1) Math.max Math 0 r - l + 1 r - l r l 1 String args[] args class Reader {
 
    private final InputStream in;
    private final byte[] buf = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    public Reader() { this(System.in);}
    public Reader(InputStream source) { this.in = source;}
 
    private boolean hasNextByte() {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    }
 
    private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
 
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
 
    private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
 
    public boolean hasNext() {skip(); 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();
        boolean minus = false;
        long num = readByte();
 
        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
 
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    }
 
    public int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    }
 
    public String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();
 
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }
 
        return sb.toString();
    }
 
    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    }
 
    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    }
 
    public void close() {try{ in.close();}catch(IOException e){ e.printStackTrace();}};
} Reader private final InputStream in; in private final byte[] buf = new byte[1024]; buf new byte[1024] 1024 private int ptr = 0; ptr 0 private int buflen = 0; buflen 0 public Reader() { this(System.in);} Reader { this(System.in);} this(System.in) this System.in System System.in public Reader(InputStream source) { this.in = source;} Reader { this.in = source;} this.in = source this.in this this.in source InputStream source source private boolean hasNextByte() {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    } hasNextByte {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    } if (ptr < buflen) return true; ptr < buflen ptr buflen return true; true ptr = 0 ptr 0 try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} IOException e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {
            buflen = in.read(buf);
        } buflen = in.read(buf) buflen in.read(buf) in.read in buf if (buflen <= 0) return false; buflen <= 0 buflen 0 return false; false return true; true private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;} readByte { if (hasNextByte()) return buf[ptr++]; else return -1;} if (hasNextByte()) return buf[ptr++]; else return -1; hasNextByte() hasNextByte return buf[ptr++]; buf[ptr++] buf ptr++ ptr return -1; -1 1 private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} isPrintableChar { return 33 <= c && c <= 126;} return 33 <= c && c <= 126; 33 <= c && c <= 126 33 <= c 33 c c <= 126 c 126 int c c private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;} skip { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;} while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++; hasNextByte() && !isPrintableChar(buf[ptr]) hasNextByte() hasNextByte !isPrintableChar(buf[ptr]) isPrintableChar(buf[ptr]) isPrintableChar buf[ptr] buf ptr ptr++ ptr public boolean hasNext() {skip(); return hasNextByte();} hasNext {skip(); return hasNextByte();} skip() skip return hasNextByte(); hasNextByte() 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();
    } next {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = readByte(); b readByte() readByte while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        } isPrintableChar(b) isPrintableChar b {
            sb.appendCodePoint(b);
            b = readByte();
        } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        boolean minus = false;
        long num = readByte();
 
        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
 
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    } nextLong {
        if (!hasNext()) throw new NoSuchElementException();
        boolean minus = false;
        long num = readByte();
 
        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
 
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() boolean minus = false; minus false long num = readByte(); num readByte() readByte if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        } num == '-' num '-' {
            num = 0;
            minus = true;
        } num = 0 num 0 minus = true minus true if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        } num < '0' || '9' < num num < '0' num '0' '9' < num '9' num {
            throw new NumberFormatException();
        } throw new NumberFormatException(); new NumberFormatException() {
            num -= '0';
        } num -= '0' num '0' while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        } true {
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        } int b = readByte(); b readByte() readByte if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException(); '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' num = num * 10 + (b - '0') num num * 10 + (b - '0') num * 10 num 10 (b - '0') b '0' if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException(); b == -1 || !isPrintableChar(b) b == -1 b -1 1 !isPrintableChar(b) isPrintableChar(b) isPrintableChar b return minus ? -num : num; minus ? -num : num minus -num num num throw new NoSuchElementException(); new NoSuchElementException() public int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    } nextInt {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    } long num = nextLong(); num nextLong() nextLong if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException(); num < Integer.MIN_VALUE || Integer.MAX_VALUE < num num < Integer.MIN_VALUE num Integer.MIN_VALUE Integer Integer.MIN_VALUE Integer.MAX_VALUE < num Integer.MAX_VALUE Integer Integer.MAX_VALUE num throw new NumberFormatException(); new NumberFormatException() return (int)num; (int)num public double nextDouble() {
        return Double.parseDouble(next());
    } nextDouble {
        return Double.parseDouble(next());
    } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    } nextChar {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() return (char)readByte(); (char)readByte() readByte public String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();
 
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }
 
        return sb.toString();
    } nextLine {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();
 
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }
 
        return sb.toString();
    } while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++; hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r') hasNextByte() hasNextByte (buf[ptr] == '\n' || buf[ptr] == '\r') buf[ptr] == '\n' buf[ptr] buf ptr '\n' buf[ptr] == '\r' buf[ptr] buf ptr '\r' ptr++ ptr if (!hasNextByte()) throw new NoSuchElementException(); !hasNextByte() hasNextByte() hasNextByte throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = readByte(); b readByte() readByte while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        } b != '\n' && b != '\r' b != '\n' b '\n' b != '\r' b '\r' {
            sb.appendCodePoint(b);
            b = readByte();
        } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    } nextIntArray {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    } int[] res = new int[n]; res new int[n] n for (int i=0; i<n; i++) res[i] = nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i res[i] = nextInt(); res[i] = nextInt() res[i] res i nextInt() nextInt return res; res int n n public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    } nextCharArray {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    } char[] res = new char[n]; res new char[n] n for (int i=0; i<n; i++) res[i] = nextChar(); int i=0; int i=0; i 0 i<n i n i++ i++ i res[i] = nextChar(); res[i] = nextChar() res[i] res i nextChar() nextChar return res; res int n n public void close() {try{ in.close();}catch(IOException e){ e.printStackTrace();}} close {try{ in.close();}catch(IOException e){ e.printStackTrace();}} try{ in.close();}catch(IOException e){ e.printStackTrace();} catch(IOException e){ e.printStackTrace();} IOException e { e.printStackTrace();} e.printStackTrace() e.printStackTrace e { in.close();} in.close() in.close in public class Main {

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);
    static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    }
} public class Main {

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);
    static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    }
} Main
import java.util.*;
import java.io.*;

public class Main {

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);
    static public void main(String args[]) {
        int n = sc.nextInt(), m = sc.nextInt();
        int l = 1, r = n;
        for (int i = 0; i < m; i++) {
            l = Math.max(l, sc.nextInt());
            r = Math.min(r, sc.nextInt());
        }
        System.out.println(Math.max(0, r - l + 1));
    }
}

class Reader {
 
    private final InputStream in;
    private final byte[] buf = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    public Reader() { this(System.in);}
    public Reader(InputStream source) { this.in = source;}
 
    private boolean hasNextByte() {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    }
 
    private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
 
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
 
    private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
 
    public boolean hasNext() {skip(); 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();
        boolean minus = false;
        long num = readByte();
 
        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
 
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    }
 
    public int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    }
 
    public String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();
 
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }
 
        return sb.toString();
    }
 
    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    }
 
    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    }
 
    public void close() {try{ in.close();}catch(IOException e){ e.printStackTrace();}};
}
