#include <bits/stdc++.h>
using namespace std;
long long h, m, h1, m1, h2, m2;
int k, y;
int diff(long long m) {
  int res = 0;
  while (m > 0) {
    res += (m % 10 != 0);
    m /= 10;
  }
  return res;
}
long long calc(long long hx, long long mx) {
  long long res = hx * ((m - 1) / (long long)(pow(10, k - 1) + 0.5));
  res += mx / (long long)(pow(10, k - 1) + 0.5);
  res += hx / (long long)(pow(10, max(0, k - y - 1)) + 0.5);
  return res;
}
int main() {
  scanf("%I64d%I64d%d", &h, &m, &k);
  scanf("%I64d%I64d%I64d%I64d", &h1, &m1, &h2, &m2);
  y = diff(m - 1);
  long long res = calc(h2, m2) - calc(h1, m1);
  if (h2 * h + m2 < h1 * h + m1) {
    res += calc(h - 1, m - 1);
    if (y + diff(h - 1) >= k) res++;
  }
  printf("%I64d", res);
  return 0;
}
