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