#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
bool Contain7(int x) {
  while (x) {
    if (x % 10 == 7) return 1;
    x /= 10;
  }
  return 0;
}
int main() {
  int x, hh, mm;
  cin >> x >> hh >> mm;
  int ans = 0;
  while (true) {
    if (Contain7(hh) || Contain7(mm)) {
      cout << ans << endl;
      break;
    }
    ans++;
    mm -= x;
    if (mm < 0) {
      mm += 60;
      hh--;
      if (hh < 0) hh += 24;
    }
  }
  return 0;
}
