#include <bits/stdc++.h>
using namespace std;
int islucky(int x, int y) {
  while (x != 0) {
    int d = x % 10;
    if (d == 7) return 1;
    x = x / 10;
  }
  while (y != 0) {
    int d = y % 10;
    if (d == 7) return 1;
    y = y / 10;
  }
  return 0;
}
int main() {
  int k;
  int hh, mm, c = 0;
  cin >> k;
  cin >> hh >> mm;
  while (islucky(hh, mm) == 0) {
    c++;
    if ((mm - k) < 0) {
      mm = 60 - (k - mm);
      hh--;
      if (hh < 0) hh = 23;
    } else {
      mm = mm - k;
    }
  }
  cout << c << endl;
}
