function Main(input) {
	input = input.trim().split(' ');
	let n = Number(input[0]);
	let k = Number(input[1]);
	
	if(k == 0){
		console.log(0);
	} else if(n >= k){
		console.log(n%k);
	} else {
		console.log(1);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));