#include <bits/stdc++.h>
bool hasSeven(int h, int m) {
  if (h % 10 == 7 || m % 10 == 7) {
    return true;
  }
  return false;
}
int main() {
  int x, a = 0;
  int h, m;
  int r = 0;
  int h1, h2;
  int m1, m2;
  while (scanf("%d", &x) != EOF) {
    scanf("%d%d", &h, &m);
    while (true) {
      if (hasSeven(h, m)) {
        break;
      }
      m -= x;
      if (m < 0) {
        h--;
        m += 60;
      }
      if (h < 0) {
        h += 24;
      }
      a++;
    }
    printf("%d\n", a);
  }
  return 0;
}
