#include <bits/stdc++.h>
using namespace std;
signed main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
  }
  long long x, h, m;
  cin >> x >> h >> m;
  long long count = 0;
  while (m % 10 != 7 && h % 10 != 7) {
    m -= x;
    while (m < 0) {
      m += 60;
      h--;
    }
    while (h < 0) h += 24;
    count++;
  }
  cout << count << "\n";
}
