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