#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int x;
  int h, m;
  while (scanf("%d", &x) != EOF) {
    int ans = 0;
    scanf("%d%d", &h, &m);
    while ((h % 10 != 7) && (m % 10) != 7) {
      if (m < x) {
        h--;
        m += 60;
      }
      if (h < 0) {
        h += 24;
      }
      m -= x;
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
