function main(input) {
  const args = input.split(' ');
  const N = args[0];
  const K = args[1];
  
  if (N % K === 0) {
    console.log(0);
  } else {
    console.log(Math.floor(N % K));
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));