#include <bits/stdc++.h>
bool src(int n1, int n2) {
  bool found = false;
  while (n2 > 0) {
    int rem = n2 % 10;
    if (rem == 7) {
      found = true;
      return found;
    }
    n2 /= 10;
  }
  while (n1 > 0) {
    int rem = n1 % 10;
    if (rem == 7) {
      found = true;
      return found;
    }
    n1 /= 10;
  }
  return found;
}
using namespace std;
int main() {
  int x, hh, mm, clicksnoo = 0;
  cin >> x;
  cin >> hh >> mm;
  while (true) {
    if (src(hh, mm))
      break;
    else {
      if (mm >= x) {
        mm -= x;
        clicksnoo++;
      } else {
        if (hh > 0) {
          hh--;
          mm += 60;
          mm -= x;
        } else {
          hh = 23;
          mm += 60;
          mm -= x;
        }
        clicksnoo++;
      }
    }
  }
  cout << clicksnoo << endl;
  return 0;
}
