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