#include <bits/stdc++.h>
int main() {
  int s;
  char hh[3], mm[3];
  int x, y, m, n, flag = 0;
  scanf("%d", &s);
  getchar();
  scanf("%s", hh);
  getchar();
  scanf("%s", mm);
  x = (hh[0] - 48) * 10 + (hh[1] - 48);
  y = (mm[0] - 48) * 10 + mm[1] - 48;
  if (hh[1] == '7' || mm[1] == '7') {
    printf("0\n");
    return 0;
  }
  m = x;
  n = y;
  while ((y % 10) != 7 && (x % 10) != 7) {
    if (y < s) {
      y += 60;
      x--;
    }
    y -= s;
    flag++;
    if (x < 0) x = 23;
  }
  printf("%d\n", flag);
  return 0;
}
