#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, hh, mm;
  while (~scanf("%d %d %d", &x, &hh, &mm)) {
    int f = 0, ans = 0;
    while (1) {
      if ((hh == 17) || (hh == 7) || (mm % 10 == 7)) break;
      ans++;
      mm -= x;
      if (mm < 0) {
        mm += 60;
        hh--;
      }
      if (hh < 0) hh = 23;
    }
    printf("%d\n", ans);
  }
  return 0;
}
