#include <bits/stdc++.h>
using namespace std;
bool f(int a) {
  bool b(0);
  while (a > 0) {
    if (a % 10 == 7) b = 1;
    a /= 10;
  }
  return b;
}
int main() {
  int x;
  cin >> x;
  int h, m;
  cin >> h >> m;
  if (f(h) || f(m)) {
    cout << 0;
  } else {
    int res(0);
    for (;; res++) {
      if (f(h) || f(m)) break;
      if (m - x >= 0)
        m -= x;
      else {
        if (h == 0)
          h = 23;
        else
          h--;
        m = 60 + m - x;
      }
    }
    cout << res;
  }
  return 0;
}
