#include <bits/stdc++.h>
using namespace std;
int is_perfect(int hh, int mm) {
  int m1 = mm % 10;
  mm = mm % 10;
  int m2 = mm % 10;
  int h1 = hh % 10;
  hh = hh / 10;
  int h2 = hh % 10;
  if (m1 == 7 || m2 == 7 || h1 == 7 || h2 == 7)
    return 1;
  else
    return 0;
}
int main() {
  int n, hh, mm, i, j;
  cin >> n;
  cin >> hh >> mm;
  int test = is_perfect(hh, mm);
  if (test)
    printf("0\n");
  else {
    i = 0;
    while (test != 1) {
      i++;
      mm = mm - n;
      if (mm < 0) {
        mm = 60 + mm;
        hh = hh - 1;
        if (hh < 0) hh = 23;
      }
      test = is_perfect(hh, mm);
    }
    printf("%d\n", i);
  }
  return 0;
}
