#include <bits/stdc++.h>
using namespace std;
int main() {
  int s1, s2, sum, T, h, m;
  cin >> T >> h >> m;
  while (1) {
    s1 = m % 10;
    s2 = h % 10;
    if (s1 == 7 || s2 == 7 || h == 7) break;
    m -= T;
    sum++;
    if (m < 0) {
      m = 60 - (-m);
      h--;
      if (h < 0) h = 24 - (-h);
    }
  }
  cout << sum;
}
