#include <bits/stdc++.h>
using namespace std;
long long H, M, K, h1, m1, h2, m2;
long long ans, digh, digm;
bool b = false;
long long cnt(int h, int m) {
  long long pw = 1, out = 0;
  int k = K;
  if (k <= 10) {
    for (int i = 1; i < k; i++) {
      pw *= 10;
    }
    out += h * ((M - 1) / pw) + m / pw;
  }
  k -= digm;
  k = max(k, 1);
  if (k <= 10) {
    pw = 1;
    for (int i = 1; i < k; i++) {
      pw *= 10;
    }
    out += h / pw;
  }
  return out;
}
int main() {
  cin >> H >> M >> K >> h1 >> m1 >> h2 >> m2;
  int x = H - 1;
  while (x) {
    digh += (x % 10 != 0);
    x /= 10;
  }
  x = M - 1;
  while (x) {
    digm += (x % 10 != 0);
    x /= 10;
  }
  if (h1 > h2)
    b = true;
  else if (h1 == h2 && m1 > m2)
    b = true;
  if (b) {
    ans += cnt(H - 1, M - 1);
    ans += (digh + digm >= K);
  }
  ans += cnt(h2, m2);
  ans -= cnt(h1, m1);
  cout << ans;
}
