#include <bits/stdc++.h>
using namespace std;
vector<int> mins = {07, 17, 27, 37, 47, 57};
int main() {
  int x;
  cin >> x;
  int hh, mm;
  cin >> hh >> mm;
  int ans;
  for (int i = 0; i < 1000; i++) {
    bool k = 0;
    for (int j = 0; j < mins.size(); j++)
      if (mm == mins[j]) k = 1;
    if (hh == 7 || hh == 17 || k) {
      ans = i;
      break;
    }
    mm -= x;
    if (mm < 0) {
      mm += 60;
      hh--;
      if (hh < 0) hh += 24;
    }
  }
  cout << ans << endl;
}
