#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, h, m, count = 0;
  ;
  cin >> x >> h >> m;
  while (1) {
    if (h % 10 == 7 || h / 10 == 7 || m % 10 == 7 || m / 10 == 7) {
      cout << count << endl;
      return 0;
    }
    count++;
    m -= x;
    while (m < 0) {
      h--;
      m += 60;
      while (h < 0) h += 24;
    }
  }
  system("pause");
  return 0;
}
