#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  int hh, mm;
  cin >> x;
  cin >> hh >> mm;
  int tmpm = mm;
  int tmph = hh;
  int cnt = 0;
  for (;;) {
    if (tmpm % 10 == 7 || tmph % 10 == 7) break;
    tmpm -= x;
    cnt++;
    if (tmpm < 0) {
      tmpm += 60;
      tmph--;
      if (tmph < 00) tmph += 24;
    }
  }
  cout << cnt << endl;
  return 0;
}
