#include <bits/stdc++.h>
int counter = 0;
void check(int hh, int mm, int snooze) {
  while (mm % 10 != 7 && hh % 10 != 7) {
    mm -= snooze;
    if (mm < 0) {
      mm = mm + 60;
      hh--;
      if (hh < 0) hh = hh + 24;
    }
    counter++;
  }
}
int main(void) {
  int snooze;
  int hh, mm;
  scanf("%d", &snooze);
  scanf("%d %d", &hh, &mm);
  check(hh, mm, snooze);
  printf("%d\n", counter);
  return 0;
}
