text_plain_output_1.png
def max_digit(n, d, r):
    max_number = -1
    n = abs(n)
    while n > 0:
        digit = n % 10
        if digit % d == r:
            if digit > max_number:
                max_number = digit
        n //= 10
    return max_number
def main():
    n = int(input())
    d = int(input())
    r = int(input())
    print(max_digit(n, d, r))
main()