#include <bits/stdc++.h>
using namespace std;
int h, m, k, dh, dm;
int h1, m1, h2, m2;
inline int dis(int now, int goal, int base) {
  int ret = 0;
  for (int i = 0; i < base; i++) {
    ret += ((now % 10) != (goal % 10));
    now /= 10;
    goal /= 10;
  }
  return ret;
}
inline int go(int now, int goal, int diff, int base) {
  if (goal < now) return 0;
  if (diff <= 1) return goal - now + 1;
  if (now != 0) return go(0, goal, diff, base) - go(0, now - 1, diff, base);
  if (diff > base) return 0;
  int pw = 1;
  for (int i = 1; i < diff; i++) pw *= 10;
  return goal / pw + (goal % pw == (pw - 1));
}
inline long long solve(pair<int, int> start, pair<int, int> end) {
  if (start == end) return 0ll;
  int h1 = start.first, m1 = start.second;
  int h2 = end.first, m2 = end.second;
  if (h1 == h2) return go(0, m2 - 1, k, dm) - go(0, m1 - 1, k, dm);
  return (long long)go(h1, h2 - 1, max(0, k - dis(m - 1, 0, dm)), dh) +
         (long long)max(0, h2 - h1 - 1) * go(0, m - 2, k, dm) +
         ((long long)go(m1, m - 2, k, dm) + go(0, m2 - 1, k, dm));
}
int main() {
  cin >> h >> m >> k;
  cin >> h1 >> m1 >> h2 >> m2;
  int tmh = h - 1;
  while (tmh) {
    tmh /= 10;
    dh++;
  }
  int tmm = m - 1;
  while (tmm) {
    tmm /= 10;
    dm++;
  }
  if (pair<int, int>(h2, m2) < pair<int, int>(h1, m1)) {
    cout << solve(pair<int, int>(h1, m1), pair<int, int>(h - 1, m - 1)) +
                solve(pair<int, int>(0, 0), pair<int, int>(h2, m2)) +
                (k <= (dis(h - 1, 0, dh) + dis(m - 1, 0, dm)))
         << endl;
    return 0;
  } else
    cout << solve(pair<int, int>(h1, m1), pair<int, int>(h2, m2)) << endl;
  return 0;
}
