#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  int x;
  cin >> x;
  int hh, mm;
  cin >> hh >> mm;
  long long ans = 0;
  if (hh % 10 == 7 || hh / 10 == 7 || mm % 10 == 7 || mm / 10 == 7) {
    cout << '0' << endl;
    return 0;
  } else {
    while (1) {
      if (hh >= 0) {
        if (mm >= 0) {
          mm -= x;
          ans++;
          if (mm < 0) {
            mm = 60 + mm, hh--;
          }
          if (hh < 0) hh = 24 + hh;
          if (hh % 10 == 7 || hh / 10 == 7 || mm % 10 == 7 || mm / 10 == 7)
            break;
        } else
          mm = 60 + mm, hh--;
      } else
        hh = 24 + hh;
    }
  }
  cout << ans << endl;
  return 0;
}
