#include <bits/stdc++.h>
using namespace std;
long long h, m, k, ah, am, bh, bm, x, y;
long long sip(long long k) {
  long long jaw = 1;
  for (long long i = 1; i <= k; i++) jaw *= 10LL;
  return jaw;
}
long long hitung(long long jam, long long men) {
  long long jaw = 0;
  long long b = (m - 1) / sip(k - 1);
  jaw += b * jam;
  long long x = m - 1;
  long long y = 0;
  while (x > 0) {
    if (x % 10 > 0) y++;
    x /= 10;
  }
  long long a = jam / sip(k - y - 1);
  jaw += a;
  jaw += men / sip(k - 1);
  return jaw;
}
int main() {
  scanf("%I64d %I64d %I64d", &h, &m, &k);
  scanf("%I64d %I64d", &ah, &am);
  scanf("%I64d %I64d", &bh, &bm);
  y = h - 1;
  while (y > 0) {
    if (y % 10 > 0) x++;
    y /= 10;
  }
  y = m - 1;
  while (y > 0) {
    if (y % 10 > 0) x++;
    y /= 10;
  }
  if (x >= k)
    y = 1;
  else
    y = 0;
  if (ah * m + am <= bh * m + bm) {
    printf("%I64d\n", hitung(bh, bm) - hitung(ah, am));
  } else {
    printf("%I64d\n",
           hitung(bh, bm) + hitung(h - 1, m - 1) - hitung(ah, am) + y);
  }
}
