#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
long long H, M;
int K;
long long calc2(int m) {
  for (int i = (1); i < (K); i++) m /= 10;
  return m;
}
int gdig(int v) {
  int dig = 0;
  while (v) {
    if (v % 10) dig++;
    v /= 10;
  }
  return dig;
}
long long calc(int h, int m) {
  int dig = gdig(M - 1);
  K -= dig;
  long long res = calc2(h);
  K += dig;
  res += calc2(m) + h * calc2(M - 1);
  return res;
}
int main() {
  long long h1, m1, h2, m2;
  cin >> H >> M >> K >> h1 >> m1 >> h2 >> m2;
  if (h1 < h2 || (h1 == h2 && m1 <= m2))
    cout << calc(h2, m2) - calc(h1, m1) << endl;
  else
    cout << ((gdig(M - 1) + gdig(H - 1) >= K) + calc(H - 1, M - 1) +
             calc(h2, m2) - calc(h1, m1))
         << endl;
  return 0;
}
