l,r,x = map(int,input().split())

for v in range(l,r+1):
    if v%x != 0:
        m=-1
    else:
        m = v
        break
print(m)