#include <bits/stdc++.h>
int main() {
  int time = 0, x, hour, minute, xhour, xminute;
  scanf("%d", &x);
  scanf("%d%d", &hour, &minute);
  xhour = hour;
  for (xminute = minute;; xminute = xminute - x) {
    if (xminute < 0) {
      xminute = xminute + 60;
      xhour--;
    }
    if (xhour < 0) xhour = xhour + 24;
    if (xhour % 10 == 7 || xminute % 10 == 7) {
      break;
    }
    time++;
  }
  printf("%d", time);
  return 0;
}
