#!/usr/bin/ruby
# encoding: utf-8


#main

# input 
N,M = gets.split.map(&:to_i)
L = Array.new(M)
R = Array.new(M)

(0..M-1).each do |i|
  L[i],R[i] = gets.split.map(&:to_i)
end

ans = 0

# maisu[i] は カード(i+1)の所持枚数
maisu = Array.new(N,0)
(0..M-1).each do |i|
  (L[i]..R[i]).each do |j|
    maisu[j-1] += 1
  end
end

(0..N-1).each do |i|
  if maisu[i] == M then 
    ans += 1
  end
end

puts ans
