#include <bits/stdc++.h>
using namespace std;
long long H, M, K, flips_per_hour;
long long num_times(long long hm, long long k) {
  if (k <= 0LL || hm == 0LL) return 0LL;
  for (long long i = 0LL; i < k - 1LL; ++i) hm /= 10LL;
  --hm;
  return (1LL + hm / 10LL) * 9LL - max(0LL, 8LL - hm % 10LL);
}
long long num_times(long long hm1, long long hm2, long long k) {
  assert(hm1 <= hm2);
  if (hm1 == hm2) return 0LL;
  return num_times(hm2, k) - num_times(hm1, k);
}
long long num_times(long long h1, long long m1, long long h2, long long m2) {
  assert(h1 <= h2);
  if (h1 == h2) return num_times(m1, m2, K);
  return num_times(m1, M - 1LL, K) + num_times(0LL, m2, K) +
         (h2 - h1 - 1LL) * num_times(0LL, M - 1LL, K) +
         num_times(h1, h2, K - flips_per_hour);
}
int main() {
  long long h1, m1, h2, m2;
  while (cin >> H >> M >> K >> h1 >> m1 >> h2 >> m2) {
    long long ret = 0LL;
    flips_per_hour = 0LL;
    for (long long temp = M - 1LL; temp > 0LL; temp /= 10LL)
      if (temp % 10LL > 0LL) ++flips_per_hour;
    long long flips_per_min = 0LL;
    for (long long temp = H - 1LL; temp > 0LL; temp /= 10LL)
      if (temp % 10LL > 0LL) ++flips_per_min;
    while (K <= 30LL) {
      if (h1 < h2 || (h1 == h2 && m1 <= m2))
        ret += num_times(h1, m1, h2, m2);
      else {
        ret += num_times(h1, m1, H - 1LL, M - 1LL) +
               num_times(0LL, 0LL, h2, m2) +
               ((K == flips_per_hour + flips_per_min) ? 1LL : 0LL);
      }
      ++K;
    }
    cout << ret << endl;
  }
}
