let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let M = input[1]

var intervals: [[Int]] = []

for _ in 0..<M {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  intervals.append([inp[0], inp[1]])
}
let startMax = intervals.map { $0[0] }.max()!
let endMin = intervals.map { $0[1] }.min()!

print(max(0, endMin - startMax + 1))
