#include <bits/stdc++.h>
using namespace std;
bool checker(int n) {
  while (n) {
    if (n % 10 == 7) {
      return 1;
    }
    n /= 10;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x;
  cin >> x;
  int hh, mm;
  cin >> hh >> mm;
  int lcount = 0;
  while (1) {
    if (checker(hh) || checker(mm)) {
      break;
    }
    mm -= x;
    lcount++;
    if (mm < 0) {
      mm = 60 - abs(mm);
      hh--;
      if (hh == -1) hh = 23;
    }
  }
  cout << lcount << endl;
  return 0;
}
