#include <bits/stdc++.h>
using namespace std;
bool test(int a) {
  if (a % 10 == 7) return true;
  if (a / 10 == 7) return true;
  return false;
}
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (test(c) || test(b)) {
    puts("0");
  } else {
    int sum = 0;
    while (!test(c) && !test(b)) {
      if (c >= a)
        c -= a;
      else if (b > 0) {
        b -= 1;
        c = (c + 60 - a);
      } else {
        b = 23;
        c = 60 + c;
        c = (c - a);
      }
      sum++;
    }
    cout << sum << endl;
  }
  return 0;
}
