#![allow(dead_code)] #![allow(unused_imports)] #![allow(unused_mut)] #![allow(unused_macros)] #![allow(unused_variables)] #![allow(non_upper_case_globals)] #![allow(non_snake_case)] #![allow(unused_unsafe)] #![allow(unused_must_use)] use std::cmp::*; use std::collections::*; use std::io::{self, stdout, BufRead, BufWriter, Write}; macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } macro_rules! dd { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("\x1b[38;5;39m|\x1b[m \x1b[38;5;39m", stringify!($a), " =\x1b[m {:?} "),*, "\x1b[38;5;69m|\x1b[m \x1b[38;5;6m"), $(&$a),*); }; } macro_rules! w { ($output:expr, $x:expr) => { let _ = writeln!($output, "{}", $x); }; } fn main() { let out = stdout(); let mut out = BufWriter::new(out.lock()); input!(n: usize, q: usize, lr: [(usize, usize); q]); let mut im = vec![0i64; n + 1]; for (l, r) in lr { im[l - 1] += 1; im[r] -= 1; let mut sm = vec![0i64; n + 1]; let mut tmp = 0; for i in 0..n + 1 { tmp += im[i]; sm[i] = tmp; } let mut ans = 0; for i in sm { ans += i % 2; } writeln!(out, "{}", ans); } }