import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let N = Int(split[0])!
let M = Int(split[1])!

//標準入力二行目以降
var ranges = [Range<Int>]()

for i in 0..<M {
    let input_line = readLine()!
    let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	let start = Int(split[0])!
	let end = Int(split[1])!
    ranges.append(start...end)
}

var returnNumberOfIDCard = 0

for i in 1...N {
	 for j in 0..<M { 
     	if ranges[j].contains(i) == false {
        	break
        } else if j == M - 1 {
        	returnNumberOfIDCard += 1
        }
     }
}
print(returnNumberOfIDCard)