#include <bits/stdc++.h>
int h, m, k, h1, m1, h2, m2;
long long cut(int a, int b) {
  for (; --b > 0; a /= 10)
    ;
  return a;
}
int ch(int a) {
  for (int ret = 0;; a /= 10)
    if (a % 10)
      ret++;
    else if (!a)
      return ret;
}
long long calc(int a, int b) {
  return cut(a, k - ch(m - 1)) + cut(m - 1, k) * a + cut(b, k);
}
int main() {
  scanf("%d%d%d%d%d%d%d", &h, &m, &k, &h1, &m1, &h2, &m2);
  if (h1 < h2 || (h1 == h2 && m1 <= m2))
    printf("%lld\n", calc(h2, m2) - calc(h1, m1));
  else
    printf("%lld\n", calc(h - 1, m - 1) + (ch(h - 1) + ch(m - 1) >= k) -
                         calc(h1, m1) + calc(h2, m2));
  return 0;
}
