#include <bits/stdc++.h>
using namespace std;
int h, m, k, h1, m1, h2, m2;
long long cut(int a, int b) {
  for (; --b > 0; a /= 10)
    ;
  return a;
}
int ch(int a) {
  for (int ret = 0;; a /= 10)
    if (a % 10)
      ret++;
    else if (!a)
      return ret;
}
long long calc(int a, int b) {
  return cut(a, k - ch(m - 1)) + cut(m - 1, k) * a + cut(b, k);
}
int main() {
  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 << calc(h - 1, m - 1) + (ch(h - 1) + ch(m - 1) >= k) - calc(h1, m1) +
                calc(h2, m2)
         << endl;
  return 0;
}
