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