#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-') c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline long long readll() {
  long long x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-') c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
bool check(int x, int y) {
  while (x) {
    if (x % 10 == 7) return 1;
    x /= 10;
  }
  while (y) {
    if (y % 10 == 7) return 1;
    y /= 10;
  }
  return 0;
}
int main() {
  int x = read(), ans = 0;
  int h = read(), m = read();
  while (1) {
    if (m < 0) m += 60, h--;
    if (h < 0) h += 24;
    if (check(h, m)) {
      printf("%d\n", ans);
      return 0;
    }
    m -= x;
    ++ans;
  }
  return 0;
}
