#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int M = 1e3 + 10;
vector<int> v[M];
int main() {
  int x, a, b, ans = 0, flag = 0;
  cin >> x >> a >> b;
  while (1) {
    if (a % 10 == 7 || b % 10 == 7) break;
    b -= x;
    while (b < 0) {
      b += 60;
      if (a >= 1)
        a -= 1;
      else
        a = 23;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}
