a = gets.chomp.to_i
(2..10**12).each do |n|
    num = []
    # lは1ずつ減っていく役
    l = n
    #1周でnumに入る数字を格納
    (1..n).each do |m|
        num <<m*l
        l = l-1
    end
    if num.include?(a) 
      puts n-1
      break
    end
end
