import random
l,r,x=map(int,input().split())
count_y=0
Y=[]
for y in range(l,r+1):
    if y % x == 0:
        count_y+=1
        Y.append(y)
if  count_y==0:
    print(-1)
elif count_y==1:
    print(Y[0])
elif count_y >1:
    print(random.choice(Y))