n,k=gets.split.map &:to_i p k<1||n<=k ? 0 : k%2==0&&k==n/2 ? n-1 : n-2