#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool good(long long a) {
  while (a > 0) {
    if (a % 10 == 7) {
      return true;
    }
    a = a / 10;
  }
  return false;
}
signed main() {
  long long x;
  cin >> x;
  long long a, b;
  cin >> a >> b;
  long long cnt = 0;
  while (good(a) == false && good(b) == false) {
    b = b - x;
    if (b < 0) {
      b += 60;
      a--;
      if (a < 0) {
        a += 24;
      }
    }
    cnt++;
  }
  cout << cnt << '\n';
}
