#include <bits/stdc++.h>
void solve(int x);
int main() {
  int x;
  while (scanf("%d", &x) != EOF) {
    solve(x);
  }
}
void solve(int x) {
  int hh, mm;
  scanf("%d%d", &hh, &mm);
  int count = 0;
  while (1) {
    if (hh == 7 || hh == 17 || mm == 7 || mm == 17 || mm == 27 || mm == 37 ||
        mm == 47 || mm == 57) {
      printf("%d\n", count);
      return;
    }
    count++;
    if ((mm - x) < 0) {
      hh--;
      if (hh < 0) hh += 24;
      mm = mm + 60 - x;
    } else {
      mm -= x;
    }
  }
}
