#include <bits/stdc++.h>
using namespace std;
bool check(int tmin) {
  int hour = tmin / 60;
  int minutes = tmin % 60;
  if (hour % 10 == 7) return true;
  if (minutes % 10 == 7) return true;
  return false;
}
int main() {
  int x;
  cin >> x;
  string s_hour, s_minutes;
  cin >> s_hour >> s_minutes;
  int hour = (s_hour[0] - '0') * 10 + s_hour[1] - '0';
  int minuts = (s_minutes[0] - '0') * 10 + s_minutes[1] - '0';
  int tmin = hour * 60 + minuts;
  int y = 0;
  while (!check(tmin)) {
    y++;
    tmin -= x;
    if (tmin < 0) tmin += 1440;
  }
  cout << y << endl;
}
