#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
bool sev(int t) {
  int m = t % 60;
  if (m % 10 == 7) return true;
  if (m / 10 == 7) return true;
  int h = t / 60;
  if (h % 10 == 7) return true;
  if (h / 10 == 7) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int x, h, m;
  cin >> x >> h >> m;
  int t = h * 60 + m, ans = 0;
  while (!sev(t)) {
    t = (t - x + 24 * 60) % (24 * 60);
    ++ans;
  }
  cout << ans << endl;
  return 0;
}
