#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, h, m, flag = 0, count = 0;
  cin >> x >> h >> m;
  int y = h;
  int z = m;
  while (flag == 0) {
    int tmp = m;
    int tmp1 = h;
    while (tmp > 0) {
      if (tmp % 10 == 7) {
        flag = 1;
        break;
      }
      tmp /= 10;
    }
    while (tmp1 && flag == 0) {
      if (tmp1 % 10 == 7) {
        flag = 1;
        break;
      }
      tmp1 /= 10;
    }
    if (flag == 1) break;
    m -= x;
    if (m < 0) {
      h--;
      if (h < 0) h += 24;
      m = 60 + m;
    }
  }
  for (int i = 0;; ++i) {
    if (y == h && z == m) break;
    m += x;
    if (m >= 60) {
      m -= 60;
      h++;
    }
    if (h > 23) {
      h -= 24;
    }
    count++;
  }
  cout << count << endl;
}
