x, y = map(int,input().split()) if 2 * x <= y: print(0) elif x < y: tmp = (2*x-y+1)//2 print(tmp) else: tmp = (y-1)//2 print(tmp)