#include <bits/stdc++.h>
using namespace std;
bool func(int n) {
  while (n) {
    if (n % 10 == 7) return true;
    n /= 10;
  }
  return false;
}
int main() {
  int h, m, x;
  cin >> x >> h >> m;
  int i, j, ans = 0;
  for (;;) {
    bool p1 = func(h);
    bool p2 = func(m);
    if (p1 || p2) {
      break;
    } else {
      if (m < x) {
        if (h == 0) {
          h = 23;
        } else {
          h--;
        }
        m = 60 - (x - m);
      } else {
        m -= x;
      }
    }
    ans++;
  }
  cout << ans << endl;
}
