use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let mut m: u64 = itr.next().unwrap().parse().unwrap(); let mut n: u64 = itr.next().unwrap().parse().unwrap(); let mut ans = 0; while m != 0 && n != 0 { if n > m { std::mem::swap(&mut m, &mut n); ans += 1; } ans += m / n; m %= n; } println!("{}", ans - 1); }