function Main(input) {
  var temp;
  var temp2;
  input = input.split("\n");
  temp = input[0].split(' ');
  temp2 = input[1].split(' ');

  var N = +temp[0];
  var K = +temp[1];
  var A1 = +temp2[0];
  var A2 = +temp2[1];
  var A3 = +temp2[2];
  var A4 = +temp2[3];
  var result;

  if((N - 1) % (K - 1) === 0) {
    result = (N - 1) % (K - 1);
    console.log(result);
  } else {
    result = (N - 1) % (K - 1) + 1;
    console.log(result);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
