#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100 + 6;
class clk {
 public:
  long long hor;
  long long mint;
  clk() {}
};
clk ck;
long long x;
void init() {
  long long th, tm;
  cin >> th >> tm;
  ck.hor = th;
  ck.mint = tm;
}
bool judge() {
  bool ok = 0;
  if (ck.hor % 10 == 7 || ck.hor / 10 == 7) return 1;
  if (ck.mint % 10 == 7 || ck.mint / 10 == 7) return 1;
  return 0;
}
void change() {
  long long th = ck.hor;
  long long tm = ck.mint;
  if (tm >= x) {
    tm -= x;
  } else if (tm < x && th >= 1) {
    th--;
    tm += 60;
    tm -= x;
  } else {
    th = 23;
    tm += 60;
    tm -= x;
  }
  ck.hor = th;
  ck.mint = tm;
}
void solve() {
  long long ans = 0;
  while (!judge()) {
    ans++;
    change();
  }
  cout << ans << endl;
}
int main(void) {
  while (cin >> x) {
    init();
    solve();
  }
  return 0;
}
