f=file("stdin","r") repeat{d=scan(f,,4) a=d[1]+d[3]*0:d[4] write(c(a[a%%d[4]==d[2]],-1)[1],1)}