#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int MAX = 1e5 + 10;
const long long mod = 1e9 + 7;
using namespace std;
int main() {
  int x;
  while (scanf("%d", &x) != EOF) {
    int t1, t2;
    scanf("%d%d", &t1, &t2);
    if (t1 % 10 == 7 || t2 % 10 == 7 || (t1 / 10) % 10 == 7 ||
        (t2 / 10) % 10 == 7) {
      printf("0\n");
      continue;
    }
    int ans = 0;
    while (1) {
      if (t2 >= x) {
        t2 -= x;
      } else {
        t1--;
        t1 = (t1 + 24) % 24;
        t2 = (t2 - x + 60) % 60;
      }
      ans++;
      if (t1 % 10 == 7 || t2 % 10 == 7 || (t1 / 10) % 10 == 7 ||
          (t2 / 10) % 10 == 7) {
        printf("%d\n", ans);
        break;
      }
    }
  }
  return 0;
}
