#include <bits/stdc++.h>
using namespace std;
long long mm[10][1000];
long long h, m, k, h1, m1, h2, m2;
long long toN(long long num, long long zs) {
  vector<long long> tmp;
  while (num) {
    long long re = num % 10;
    tmp.push_back(re);
    num /= 10;
  }
  long long ans = 0;
  for (int i = (int)tmp.size() - 1; i >= 0; i--) {
    if (i == 0) {
      if (zs <= 1) ans += tmp[i];
    } else {
      ans += mm[i][zs] * tmp[i];
    }
  }
  return ans;
}
long long cal(long long h1, long long m1) {
  long long ret = 0;
  long long tmp = toN(m - 1, k);
  ret += h1 * tmp;
  tmp = toN(m1, k);
  ret += tmp;
  tmp = m - 1;
  long long cnt = 0, cz = 0;
  while (tmp) {
    long long re = tmp % 10;
    if (!re) cz++;
    cnt++;
    tmp /= 10;
  }
  cnt = cnt - cz;
  long long zs = max((long long)0, k - cnt);
  tmp = toN(h1, zs);
  ret += tmp;
  return ret;
}
bool less1(long long h1, long long m1, long long h2, long long m2) {
  if (h1 != h2)
    return h1 < h2;
  else
    return m1 < m2;
}
int main() {
  scanf("%lld%lld%lld%lld%lld%lld%lld", &h, &m, &k, &h1, &m1, &h2, &m2);
  memset(mm, 0, sizeof(mm));
  for (int i = 1; i <= 9; i++) {
    int base = 9;
    for (int j = 1; j < i; j++) base *= 10;
    for (int j = 1; j <= i; j++) {
      mm[i][j] = base, base = base / 10;
    }
    mm[i][i + 1] = 1;
  }
  for (int i = 1; i <= 8; i++) {
    for (int j = i; j >= 0; j--) mm[i][j] = mm[i][j] + mm[i][j + 1];
  }
  bool dd = less1(h2, m2, h1, m1);
  if (!dd) {
    long long t2 = cal(h2, m2), t1 = cal(h1, m1);
    printf("%lld\n", t2 - t1);
  } else {
    long long tmp = 0;
    long long cnt = 0, cz = 0;
    tmp = h - 1;
    while (tmp) {
      long long re = tmp % 10;
      if (!re) cz++;
      cnt++;
      tmp /= 10;
    }
    tmp = m - 1;
    while (tmp) {
      long long re = tmp % 10;
      if (!re) cz++;
      cnt++;
      tmp /= 10;
    }
    if (cnt - cz >= k)
      tmp = 1;
    else
      tmp = 0;
    long long t1 = cal(h1, m1), t2 = cal(h - 1, m - 1), t3 = cal(h2, m2);
    printf("%lld\n", t2 - t1 + tmp + t3);
  }
  return 0;
}
