#include <bits/stdc++.h>
using namespace std;
bool check7(int hr, int min) {
  while (hr > 0) {
    int dig = hr % 10;
    if (dig == 7) return true;
    hr /= 10;
  }
  while (min > 0) {
    int dig = min % 10;
    if (dig == 7) return true;
    min /= 10;
  }
  return false;
}
int main() {
  int x;
  cin >> x;
  int hr, min;
  cin >> hr >> min;
  int nsnooze = 0;
  if (check7(hr, min))
    cout << 0;
  else {
    while (1) {
      min -= x;
      if (min < 0) {
        hr = hr - 1;
        min = 60 + min;
        if (hr < 0) {
          hr = 24 + hr;
        }
      }
      nsnooze++;
      if (check7(hr, min)) {
        cout << nsnooze;
        break;
      }
    }
  }
}
