#include <bits/stdc++.h>
using namespace std;
long long h, m, i, j, k;
long long p10(long long x) {
  long long t = 1;
  for (long long i = 0; i < x; i++) t *= 10;
  return t;
}
long long f(long long x) {
  long long t = 0;
  for (long long i = 9; i >= k - 1; i--) {
    long long c = x / p10(i) % 10;
    t += c * p10(i - k + 1);
  }
  return t;
}
int main() {
  long long mh = 0, hd = 0;
  scanf("%I64d %I64d %I64d", &h, &m, &k);
  for (i = 1; i <= 10; i++) {
    long long t = (m - 1) / p10(i - 1) % 10;
    if (t != 0) mh++;
    t = (h - 1) / p10(i - 1) % 10;
    if (t != 0) hd++;
  }
  long long h1, m1, h2, m2;
  scanf("%I64d %I64d", &h1, &m1);
  scanf("%I64d %I64d", &h2, &m2);
  long long ans = 0;
  if (h2 > h1 || (h2 == h1 && m2 >= m1))
    ans += (h2 - h1) * f(m - 1) - f(m1) + f(m2);
  else
    ans += (h2 + h - h1) * f(m - 1) - f(m1) + f(m2);
  k -= mh;
  if (k < 1) k = 1;
  if (h2 > h1 || (h2 == h1 && m2 >= m1))
    ans += f(h2) - f(h1);
  else {
    ans += f(h - 1) - f(h1) + f(h2);
    if (hd >= k) ans++;
  }
  printf("%I64d\n", ans);
  return 0;
}
