#include <bits/stdc++.h>
using namespace std;
int x, ans = 0;
int h, m;
int main() {
  cin >> x;
  cin >> h >> m;
  while (1) {
    string hh = to_string(h);
    string mm = to_string(m);
    if (hh[0] == '7' || hh[1] == '7' || mm[0] == '7' || mm[1] == '7') break;
    ans++;
    m = m - x;
    if (m < 0) {
      m = 60 - abs(m);
      h--;
    }
    if (h <= 0) h = 24 - abs(h);
  }
  cout << ans;
  return 0;
}
