from collections import defaultdict, Counter, deque from itertools import groupby, accumulate, combinations, permutations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from operator import itemgetter import math from heapq import heapify, heappush, heappop LMI=lambda:list(map(int, input().split())) LMS=lambda:list(map(str, input().split())) MI=lambda:map(int, input().split()) MS=lambda:map(str, input().split()) II=lambda:int(input()) IS=lambda:input().split() LI=lambda:list(input()) X,N=MI() minus=False if X<0: minus=True X=abs(X) # def calc(x, n): # tmp=n*(n + 1)//2 # if x<=0: # if x+tmp<=0: # return x + tmp # else: # y=(x + tmp)//2 # return (x + tmp)-2*y # else: # if x - tmp > 0: # return x - tmp # else: # y=(-x + tmp)//2 # return (x - tmp) + 2*y #OK、NGを判断するための関数 def cond(X, N): return X >= N*(N+1)//2 ok, ng = 0, 10**18+1 #okとngの値が連番になるまで繰り返す while abs(ok - ng)>1: #真ん中の値を計算 mi = (ok + ng) // 2 #条件判断の関数を使う if cond(X, mi): #okなら真ん中の値をokにし狭める ok = mi else: #ngなら真ん中の値をngにし狭める ng = mi if ok>N: print(X - N*(N + 1)//2) exit() else: cnt=N-ok now=X-ok*(ok + 1)//2 if cnt%2==0: if minus: print(-1*(now+cnt//2)) else: print(now+cnt//2) else: if minus: print(-1*(now-(ok+1)-(cnt-1)//2)) else: print(now-(ok+1)-(cnt-1)//2)