fn main() { let mut nq = String::new(); std::io::stdin().read_line(&mut nq).ok(); let nq: Vec = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nq[0]; let q = nq[1]; let pairs = (0..q).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1]) }) .collect::>(); let mut lights = vec![false; n]; let mut cnt = 0usize; for &(l, r) in pairs.iter() { for i in l..r { if lights[i] { cnt -= 1; } else { cnt += 1; } lights[i] = !lights[i]; } println!("{}", cnt); } }