N, K = map(int, raw_input().split()) print 0 if N == 2 and K == 1 else N-1