function Main(input) {
  let inputs = input.split(" ");
  int h1 = inputs[0];
  int m1 = inputs[1];
  int h2 = inputs[2];
  int m2 = inputs[3];
  int k = inputs[4];
  
  int minute1 = h1 * 60 + m1;
  int minute2 = h2 * 60 + m2;
  
  int difference = minute2 - minute1;
  console.log(difference % k * k);
}  
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
