#include <bits/stdc++.h>
using namespace std;
int h, m, K, h1, m1, h2, m2, Y1, Y2;
long long pw10[20];
inline long long gettime(int x, int y) { return 1ll * x * m + y; }
inline long long f(int x, int y) {
  return 1ll * x * ((m - 1) / pw10[min(K - 1, 18)]) +
         (y / pw10[min(K - 1, 18)]) + (x / pw10[min(max(0, K - Y1 - 1), 18)]);
}
int main() {
  pw10[0] = 1;
  for (int i = 1; i < 19; i++) pw10[i] = pw10[i - 1] * 10;
  scanf("%d%d%d", &h, &m, &K);
  scanf("%d%d", &h1, &m1);
  scanf("%d%d", &h2, &m2);
  int tmp = m - 1;
  while (tmp) {
    Y1 += ((tmp % 10) != 0);
    tmp /= 10;
  }
  tmp = h - 1;
  while (tmp) {
    Y2 += ((tmp % 10) != 0);
    tmp /= 10;
  }
  if (gettime(h1, m1) <= gettime(h2, m2))
    printf("%lld\n", f(h2, m2) - f(h1, m1));
  else
    printf("%lld\n",
           f(h2, m2) - f(h1, m1) + f(h - 1, m - 1) + ((Y1 + Y2) >= K));
  return 0;
}
