#include <bits/stdc++.h>
using namespace std;
bool lucky(int a) {
  if (a % 10 == 7) return true;
  a /= 10;
  return a % 10 == 7;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x;
  cin >> x;
  int hours, minutes;
  cin >> hours >> minutes;
  int y = 0;
  while (!lucky(hours) && !lucky(minutes)) {
    minutes -= x;
    if (minutes < 0) {
      --hours;
      minutes += 60;
      if (hours < 0) hours += 24;
    }
    ++y;
  }
  cout << y << '\n';
  return 0;
}
