#!/usr/bin/env python

A = int(raw_input())
B = int(raw_input())
M = int(raw_input())


ans = 0

def is_zig_zag(d):
  s = str(d)
  if len(s) == 1: return True
  if s[0] < s[1]:
    b = True
  elif s[0] > s[1]:
    b = False
  else:
    return False

  for i in xrange(1, len(s)):
    if not b and s[i-1] <= s[i]: return False
    if     b and s[i-1] >= s[i]: return False
    b = not b
  return True

for i in xrange(A, B+1, M):
  if (is_zig_zag(i)):
    ans = (ans + 1) % 10000

print ans