#include <bits/stdc++.h>
using namespace std;
int Snooze(int x, int hh, int mm) {
  int cnt = 0;
  while (true) {
    if ((mm == 7 || mm == 17 || mm == 27 || mm == 37 || mm == 47 || mm == 57)) {
      break;
    }
    if ((hh == 7 || hh == 17 || hh == 27 || hh == 37 || hh == 47 || hh == 57)) {
      break;
    } else {
      mm -= x;
      cnt++;
      if (mm < 0) {
        mm = 60 + mm;
        hh--;
      }
      if (hh < 0) {
        hh = 23;
      }
    }
  }
  return cnt;
}
int main() {
  int x, hh, mm;
  cin >> x >> hh >> mm;
  cout << Snooze(x, hh, mm) << endl;
  return 0;
}
