#include <bits/stdc++.h>
using namespace std;
int n, m;
int x;
bool ok(int a) {
  if (a == 7 || a == 17 || a == 27 || a == 37 || a == 47 || a == 57) return 1;
  return 0;
}
int main() {
  while (scanf("%d%d%d", &x, &n, &m) != EOF) {
    int flag = 0;
    while (1) {
      if (m < 0) n -= 1, m += 60;
      if (n < 0) n += 24;
      if (ok(n) || ok(m))
        break;
      else {
        m -= x;
        flag++;
        if (m < 0) n -= 1, m += 60;
        if (n < 0) n += 24;
      }
    }
    cout << flag << endl;
  }
  return 0;
}
