#include <bits/stdc++.h>
using namespace std;
template <class T>
T min3(T a, T b, T c) {
  return min(a, min(b, c));
};
template <class T>
T max3(T a, T b, T c) {
  return max(a, max(b, c));
};
void openFile() {
  freopen("/home/khaihanhdk/MyWorkplace/cpp file/a.inp", "r", stdin);
}
bool con7(int h, int k) {
  return (k % 10 == 7 || k / 10 == 7 || h % 10 == 7 || h / 10 == 7);
}
bool findTime(int h, int k, int x, int y) {
  int l = x * y;
  int m = l / 60;
  m %= 24;
  h = (h - m + 24) % 24;
  l %= 60;
  if (l > k) {
    h = h - 1;
    if (h == -1) h = 23;
    k = 60 + k - l;
  } else
    k -= l;
  return con7(h, k);
}
int main() {
  int x, h, k;
  cin >> x;
  cin >> h >> k;
  for (int i = 0; i <= 1000000000; i++) {
    if (findTime(h, k, x, i)) {
      cout << i;
      return 0;
    }
  }
}
