main(n,k){scanf("%d%d",&n,&k);printf("%d",!k|k>n++?0:n-3+!(n-k-k));}