#include <bits/stdc++.h>
using namespace std;
inline void getint(int& x) {
  int f = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline void getll(long long& x) {
  long long f = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline void writeint(int& x) {
  if (!x) {
    printf("0");
    return;
  } else if (x < 0)
    printf("-");
  int tmp = x < 0 ? -x : x, digit[17] = {0};
  while (tmp) {
    digit[++digit[0]] = tmp % 10;
    tmp /= 10;
  }
  for (int(i) = (digit[0]); (i) >= (1); --(i)) printf("%d", digit[i]);
}
inline void writell(long long& x) {
  if (!x) {
    printf("0");
    return;
  } else if (x < 0)
    printf("-");
  long long tmp = x < 0 ? -x : x;
  int digit[27] = {0};
  while (tmp) {
    digit[++digit[0]] = tmp % 10;
    tmp /= 10;
  }
  for (int(i) = (digit[0]); (i) >= (1); --(i)) printf("%d", digit[i]);
}
int x, h, m, ans;
int check(int x, int y) {
  int p = x, q = y;
  while (p) {
    if (p % 10 == 7) return 1;
    p /= 10;
  }
  while (q) {
    if (q % 10 == 7) return 1;
    q /= 10;
  }
  return 0;
}
int main() {
  getint(x), getint(h), getint(m);
  while (1) {
    if (check(h, m)) return writeint(ans), 0;
    m -= x;
    ans++;
    if (m < 0) h--, m += 60;
    if (h < 0) h += 24;
  }
  return 0;
}
