#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x, h, m;
  cin >> x >> h >> m;
  int ans = 0;
  while (1) {
    if (h % 10 == 7 || h / 10 == 7) return cout << ans, 0;
    if (m % 10 == 7 || m / 10 == 7) return cout << ans, 0;
    ans++;
    if (x > m) {
      m = 60 + m - x;
      if (h > 0)
        h--;
      else
        h = 23;
    } else
      m -= x;
  }
  return 0;
}
