x, n = map(int, input().split()) if x < 0: f = 0 x *= -1 else: f = 1 def is_ok(arg): S = arg * (arg + 1) // 2 return S <= abs(x) def bs(ok, ng): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok m = bs(0, 10**9 * 2) if n <= m+1: S = n * (n+1) // 2 x += (-1) ** f * S print(x) exit() S = (m+2) * (m+1) // 2 x += (-1) ** f * S n -= m+1 if n % 2: x *= -1 n = -(-n//2) if x < 0: x = -(abs(x) + n) else: x = x + n print(x)