#include <bits/stdc++.h>
using namespace std;
bool good(int num) {
  while (num) {
    if (num % 10 == 7) return 1;
    num /= 10;
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  int x, h, m;
  cin >> x >> h >> m;
  int cnt = 0;
  while (1) {
    if (good(h) || good(m)) {
      cout << cnt << endl;
      return 0;
    }
    m -= x;
    if (m < 0) m += 60, h--;
    if (h < 0) h += 24;
    cnt++;
  }
}
