#include <bits/stdc++.h>
using namespace std;
bool check(int n) {
  while (n) {
    int rem = n % 10;
    n = n / 10;
    if (rem == 7) return true;
  }
  return false;
}
int main() {
  int x, hh, mm, ans(0);
  cin >> x >> hh >> mm;
  while (!check(hh) and !check(mm)) {
    ans++;
    if (mm >= x)
      mm -= x;
    else if (mm < x and hh > 0) {
      hh--;
      mm = 60 - (x - mm);
    } else if (mm < x and hh == 0) {
      mm = 60 - (x - mm);
      hh = 23;
    }
  }
  cout << ans << endl;
}
