#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int neg = 0, c = getchar();
  x = 0;
  while ((c < '0' or c > '9') and (c != '-')) c = getchar();
  if (c == '-') neg = 1, c = getchar();
  while (c >= '0' and c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (neg) x = -x;
}
inline void writeln(int x) {
  int neg = 0, i = 0;
  char buffor[21];
  if (x < 0) neg = 1, x = -x;
  do {
    buffor[++i] = x % 10 + '0';
    x /= 10;
  } while (x);
  if (neg) putchar('-');
  while (i) putchar(buffor[i--]);
  putchar('\n');
}
int x, hh, mm;
void input() {
  cin >> x;
  cin >> hh >> mm;
}
void solve() {
  int res = 0;
  while (1) {
    if (hh == 7 or hh == 17 or mm % 10 == 7) break;
    mm -= x;
    if (mm < 0) mm += 60, hh--;
    if (hh < 0) hh += 24;
    res++;
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  solve();
  return 0;
}
