Scanf.scanf "%d %d" @@ fun n m ->
let lr = Array.init m (fun _ -> Scanf.scanf " %d %d" (fun l r -> l, r)) in
let lM = Array.fold_left (fun lM (l, _) -> max lM l) 0 lr in
let rm = Array.fold_left (fun rm (_, r) -> min rm r) n lr in
Printf.printf "%d\n" (max 0 (rm - lM + 1))
