a,b,c = map(int,input().split())for i in [a,b]:    if i%c==0:        print(i)        breakelse:    print(-1)