#include <bits/stdc++.h>
bool sev(int h, int m);
using namespace std;
int main() {
  int snooze;
  cin >> snooze;
  int h;
  int m;
  int n = 0;
  cin >> h >> m;
  if (sev(h, m)) {
    cout << "0" << endl;
  } else {
    while (sev(h, m) == false) {
      if (m >= snooze) {
        m = m - snooze;
      } else {
        if (h == 0) h = 24;
        int x = snooze;
        x = x - m;
        h = h - 1;
        m = 60;
        m = m - (x);
      }
      n++;
    }
    cout << n;
  }
  return 0;
}
bool sev(int h, int m) {
  if (h % 10 == 7 || h / 10 % 10 == 7 || m % 10 == 7 || m / 10 % 10 == 7)
    return true;
  else
    return false;
}
