#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
bool ok(int a) {
  for (int i = 0; i <= 50; i += 10) {
    if (a == i + 7) return true;
  }
  return false;
}
int main() {
  base();
  int x, a, b;
  cin >> x >> a >> b;
  int ans = 0;
  while (!ok(a) && !ok(b)) {
    b -= x;
    if (b < 0) b += 60, a--;
    if (a < 0) a += 24;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
