print<>!~/ .* /,($'/$`.$/)[$'%$`|$&<$'].($d/$`.$/)[($d=$&+$')%$`]||-1