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