#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4.0;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
const long double EPS = 0.0000001;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int a, b, n, cnt = 0;
  cin >> n;
  cin >> a >> b;
  if (a % 10 == 7 || b % 10 == 7)
    cout << 0 << endl;
  else {
    while (1) {
      b = b - n;
      if (b < 0) {
        a = a - 1;
        b = 60 + b;
        if (a < 0) a = a + 24;
      }
      cnt++;
      if (a % 10 == 7 || b % 10 == 7) {
        cout << cnt << endl;
        return 0;
      }
    }
  }
  return 0;
}
