#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, hh, mm, cnt = 0;
  cin >> x >> hh >> mm;
  if (hh % 10 == 7 || mm % 10 == 7)
    cout << "0";
  else {
    while (1) {
      if (mm <= x - 1 && mm >= 0) {
        mm = mm - x + 60;
        if (hh == 0)
          hh = hh - 1 + 24;
        else
          hh -= 1;
      } else {
        mm -= x;
      }
      cnt++;
      if (hh % 10 == 7 || mm % 10 == 7) {
        cout << cnt;
        return 0;
      }
    }
  }
  return 0;
}
