def main():
    A = int(input())
    B = int(input())
    M = int(input())

    num = []
    for x in range(A, B + 1):
        if x % M == 0:
            num.append(x)
        else:
            pass

    cnt = 0
    for x in range(len(num)):
        num[x] = list(str(num[x]))
        c = len(num[x]) #checker
        if c == 1:
            cnt += 1
        elif c == 2:
            if num[x][0] == num[x][1]:
                pass
            else:
                cnt += 1
        elif c >= 3:
            if num[x][0] == num[x][1]:
                pass
            elif num[x][0] > num[x][1]:
                listcnt = 0
                for y in range(1, len(num[x]) - 1):
                    if y % 2 != 0:
                        if num[x][y] < num[x][y + 1]:
                            listcnt += 1
                        else:
                            break
                    if y % 2 == 0:
                        if num[x][y] > num[x][y + 1]:
                            listcnt += 1
                        else:
                            break
                if listcnt == len(num[x]) - 2:
                    cnt += 1
            elif num[x][0] < num[x][1]:
                listcnt = 0
                for y in range(1, len(num[x]) - 1):
                    if y % 2 != 0:
                        if num[x][y] > num[x][y + 1]:
                            listcnt += 1
                        else:
                            break
                    if y % 2 == 0:
                        if num[x][y] < num[x][y + 1]:
                            listcnt += 1
                        else:
                            break
                if listcnt == len(num[x]) - 2:
                    cnt += 1
        #hoge = ""
        #for y in range(len(num[x])):
        #    hoge += num[x][y]
        #num[x] = int(hoge)

    ans = cnt % 10000
    print(ans)


if __name__ == "__main__":
    main()