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