#include <bits/stdc++.h>
using namespace std;
const long long INF = (1ll << 62) - 1;
const int inf = (1 << 30) - 1;
int cnt;
int main() {
  ios_base::sync_with_stdio(false);
  int x;
  cin >> x;
  int a, b;
  cin >> a >> b;
  while (1) {
    if (a % 10 == 7 || b % 10 == 7) break;
    cnt++;
    b -= x;
    if (b < 0) {
      b += 60;
      a--;
    }
    if (a < 0) a += 24;
  }
  cout << cnt << endl;
}
