#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
void solve() {
  long long x;
  cin >> x;
  long long hh, mm;
  cin >> hh >> mm;
  long long ans = 0;
  long long a = hh, b = mm;
  string s = to_string(a) + ":" + to_string(b);
  while (s.find('7') == -1) {
    if (a > 0 && b - x < 0) {
      a--;
      b = 60 - (x - b);
    } else if (a == 0 && b - x < 0) {
      a = 23;
      b = 60 - (x - b);
    } else {
      b -= x;
    }
    s = to_string(a) + ":" + to_string(b);
    ans++;
    if (s.find('7') != -1) break;
  }
  cout << ans << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
