use std::io; use std::str::FromStr; fn main() { let stdin = io::stdin(); let mut buf = String::new(); stdin.read_line(&mut buf).ok(); let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap()); let num = it.next().unwrap(); let mut ans = -1000; for _ in 0..num { let mut buf = String::new(); stdin.read_line(&mut buf).ok(); let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap()); let (a, b) = (it.next().unwrap(), it.next().unwrap()); let tmp = b - a; if ans == -1000 { ans = tmp; continue; } if ans != tmp { println!("-1"); return; } } if ans <= 0 { println!("{}", -1); return; } println!("{}", ans); }