#include <bits/stdc++.h>
using namespace std;
int x;
int hh, mm;
void gettime() {
  int time = hh * 60 + mm;
  time -= x;
  if (time < 0) {
    time = time + 24 * 60;
  }
  mm = time % 60;
  hh = time / 60;
}
bool check() {
  if (hh % 10 == 7 || mm % 10 == 7) {
    return true;
  }
  return false;
}
int main() {
  cin >> x >> hh >> mm;
  int ans = 0;
  while (!check()) {
    ans++;
    gettime();
  }
  cout << ans << endl;
}
