#include <bits/stdc++.h>
using namespace std;
typedef struct struct1 {
  int val, num;
} struct1;
bool compare(struct1 lhs, struct1 rhs) { return lhs.val < rhs.val; }
int check(int t) {
  while (t) {
    if (t % 10 == 7) {
      return 1;
    }
    t = t / 10;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int h, m;
  cin >> h >> m;
  int count = 0;
  while (1) {
    if (check(m) == 1 || check(h) == 1) break;
    if (m - n < 0) {
      m += 60;
      if (h == 0) h = 24;
      h--;
    }
    m -= n;
    count++;
  }
  cout << count;
  return 0;
}
