N = gets.to_i K = gets.to_i Quotient = "285714" case n = N % Quotient.size when 1, 3, 4 then puts Quotient[n - 1] when 2 then if K.odd? then puts Quotient[1] else puts Quotient[3] end when 5 then if K.odd? then puts Quotient[4] else puts Quotient[0] end when 0 then puts Quotient[5] end