#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const double PI = acos(-1.0);
const long long mod = 1000000007;
const long long INF = 1e9;
const long long LINF = 1e18;
pair<int, int> sub(pair<int, int> curr, int min) {
  if (curr.second >= min)
    curr.second -= min;
  else {
    curr.second += (60 - min);
    curr.first--;
    if (curr.first < 0) curr.first += 24;
  }
  return curr;
}
bool is(pair<int, int> x) {
  if (x.first % 10 == 7) return 1;
  if (x.second % 10 == 7) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int x, h, m;
  cin >> x >> h >> m;
  int y = 0;
  pair<int, int> curr = make_pair(h, m);
  while (1) {
    bool ok = 0;
    if (is(curr)) ok = 1;
    if (ok) {
      cout << y;
      return 0;
    }
    curr = sub(curr, x);
    ++y;
  }
  return 0;
}
