s = gets.chomp
t = gets.chomp

if s.scan(t).join() == s || t.scan(s).join() == t || s.chars.uniq == t.chars.uniq
  puts -1
else
  st = s.gsub(t," ")
  ts = t.gsub(s," ")
  if (st*2).gsub(t," ").gsub(/\s+/," ") == st.gsub(/\s+/," ") ||
     (ts*2).gsub(t," ").gsub(/\s+/," ") == ts.gsub(/\s+/," ")
    #1. -> 無限
    puts -1
  else
    #2. -> 有限
    #puts (st*2).scan(/\s+/)&.max&.size || (ts*2).scan(/\s+/)&.max&.size.to_i
    if (st*2).scan(/\s+/)&.max&.size
      puts (st*2).scan(/\s+/)&.max&.size
    else
      puts (ts*2).scan(/\s+/)&.max&.size.to_i
    end
  end
end