#include <bits/stdc++.h>
using namespace std;
long long H, M;
int K;
long long h1, m1, h2, m2;
long long Comp(long long h, long long m);
long long Cal(long long h, long long m);
int CalDigit(long long so);
long long Solve(long long so, int d);
int main() {
  cin >> H >> M >> K;
  cin >> h1 >> m1 >> h2 >> m2;
  if (Comp(h1, m1) <= Comp(h2, m2)) {
    cout << Cal(h2, m2) - Cal(h1, m1) << endl;
  } else {
    cout << Cal(H - 1, M - 1) - Cal(h1, m1) + Cal(h2, m2) +
                (CalDigit(M - 1) + CalDigit(H - 1) >= K)
         << endl;
  }
  return 0;
}
long long Cal(long long h, long long m) {
  int d = CalDigit(M - 1);
  long long Ans = Solve(h, K - d);
  Ans = Ans + Solve(m, K) + h * Solve(M - 1, K);
  return Ans;
}
long long Solve(long long so, int d) {
  for (int i = 0; i < d - 1; i++) {
    so /= 10;
  }
  return so;
}
int CalDigit(long long so) {
  int d = 0;
  while (so > 0L) {
    if (so % 10L) d++;
    so /= 10;
  }
  return d;
}
long long Comp(long long h, long long m) { return h * H + m; }
