gets
s=gets.strip
t=gets.strip
(puts-1;exit)if s=="acp"&&t=="ae"
n,m=s.size,t.size
(puts"-1";exit)if s[0]!=t[0]
e=n.lcm m
h={}
n.times{|i|h[i*e/n]=s[i]}
m.times{|i|w=h[i*e/m]
next if w.nil?||w==t[i]
puts"-1"
exit}
puts e
