x, n = gets.split.map(&:to_i) y = x.abs ac = n wa = -1 while ac - wa > 1 wj = (ac + wa) >> 1 sum = (1 .. wj).sum if sum >= y ac = wj else wa = wj end end ac = [ac - 1, 0].max current = x <= 0 ? x + (1 .. ac).sum : x - (1 .. ac).sum e = (n - ac) / 2 o = (n - ac) % 2 if current <= 0 current -= e current += n if o == 1 else current += e current -= n if o == 1 end puts current