fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let judge = |p| { if p <= 1 { return false } let x = n % p; let mut y = n; while y > 0 { if y % p != x { return false } y /= p; } true }; let mut ans: usize = n - 1; if n == 2 { ans = 3 } else { for i in (1..).take_while(|x| x * x <= n) { if judge(i) { ans = i; break; } if n % i == 0 { let p = n / i - 1; if p > 1 && judge(p) { ans = p } } } }; println!("{}", ans); }