#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, h, m, cou = 0;
  cin >> x;
  cin >> h >> m;
  while (h <= 45) {
    if (h % 10 == 7) break;
    while (m >= 0) {
      if (m % 10 == 7) {
        break;
      }
      m -= x;
      cou++;
    }
    if (m >= 0) break;
    h--;
    if (h < 0) h = 23;
    m = 60 + m;
  }
  cout << cou;
  cin >> x;
}
