#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
const int INF = int(1e9);
int main() {
  int n;
  char str1[maxn], str2[maxn];
  while (~scanf("%d", &n)) {
    scanf("%s %s", str1, str2);
    int h, m;
    h = (str1[0] - '0') * 10 + str1[1] - '0';
    m = (str2[0] - '0') * 10 + str2[1] - '0';
    int ans = 0;
    while (h % 10 != 7 && m % 10 != 7) {
      if (m - n < 0) {
        m = m - n + 60;
        if (h == 0)
          h = 23;
        else
          h--;
      } else
        m = m - n;
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
