#include <bits/stdc++.h>
using namespace std;
bool seven(int n) {
  while (n) {
    if (n % 10 == 7) return 0;
    n /= 10;
  }
  return 1;
}
int main() {
  int x, xCopy, cnt = 0;
  int h, m;
  cin >> x;
  cin >> h >> m;
  xCopy = x;
  while (seven(h) && seven(m)) {
    if (x > m) {
      xCopy -= m;
      m = 60;
      m -= xCopy;
      if (h == 0)
        h = 23;
      else
        h -= 1;
      xCopy = x;
    } else
      m -= x;
    cnt++;
  }
  cout << cnt;
  return 0;
}
