extension String {
    func split(separator: String) -> [String] {
        return self.characters.split(separator)
    }
}

func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}


/************** main *****************/

let nm = readIntSplit(by: " ")
let (n, m) = (nm[0], nm[1])
var (t, b) = (1, n)
for i in 1...m {
    let lr = readIntSplit(by: " ")
    let (l, r) = (lr[0], lr[1])
    if t < l{
        t = l
    }
    if b > r {
        b = r
    }
}
let ans = b - t + 1
if ans < 0 {
    print(0)
} else {
    print(ans)
}
