#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int a[MAXN];
bool judge(int hh, int mm) {
  bool flag = false;
  if (hh % 10 == 7) flag = true;
  if (hh / 10 == 7) flag = true;
  if (mm % 10 == 7) flag = true;
  if (mm / 10 == 7) flag = true;
  return flag;
}
int main() {
  int x;
  while (scanf("%d", &x) != EOF) {
    int hh, mm;
    scanf("%d%d", &hh, &mm);
    int ans = 0;
    while (!judge(hh, mm)) {
      mm = mm - x;
      if (mm < 0) mm += 60, hh--;
      if (hh < 0) hh += 24;
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
