#include <bits/stdc++.h>
using namespace std;
bool contains7(int a) {
  if (a % 10 == 7) return true;
  a -= (a % 10);
  a /= 10;
  if (a == 7) return true;
  return false;
}
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while (true) {
    if (contains7(b) || contains7(c)) {
      break;
    }
    if (c - a < 0) {
      c = (c - a + 60);
      if (b - 1 < 0) {
        b = (b - 1 + 24);
      } else {
        b = b - 1;
      }
    } else {
      c = c - a;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}
