lis = list(map(int,input().split())) if(lis[0]%lis[1] == 0 and lis[0]/lis[1] == 2): print(0) else: if(lis[0]%lis[1] == 0): print(int((lis[0]/2)//lis[1]*lis[1]-lis[1])) else: print(int((lis[0]/2)//lis[1]*lis[1]))