#include <bits/stdc++.h>
int isZigzagNumber(int);
int main() {
  int s, e, M, cnt = 0;
  fscanf(stdin, "%d\n%d\n%d", &s, &e, &M);
  if (s % M) s = s + (M - (s % M));
  while (s <= e) {
    if (isZigzagNumber(s)) cnt++;
    s += M;
  }
  fprintf(stdout, "%d\n", cnt % 10000);
  return 0;
}
int isZigzagNumber(int n) {
  int a, b, c;
  a = n % 10;
  b = (n / 10) % 10;
  c = (n / 100) % 10;
  if (n < 10)
    return 1;
  else if (n < 100) {
    if (a == b)
      return 0;
    else
      return 1;
  }
  if (a == b || b == c) return 0;
  int x = a > b, y = b > c;
  if (x == y)
    return 0;
  else
    isZigzagNumber(n / 10);
}
