n = gets.to_i sn = n * (n - 1) / 2 while true do m = sn % n if m == 0 then break end sn = n n = m end puts n