#include <bits/stdc++.h>
using namespace std;
int x, h, m, i, cnt;
int main() {
  cin >> x;
  cin >> h >> m;
  while (h % 10 != 7 && m % 10 != 7) {
    if (m < x) {
      if (h > 0)
        h--;
      else
        h = 23;
      m = 60 + m - x;
    } else
      m -= x;
    cnt++;
  }
  cout << cnt;
}
