local s = io.read()
local t = io.read()
local swapped = false
if #s < #t then
  swapped = true
  s, t = t, s
end
local slen = #s
local tlen = #t
s = s .. s

local mma = math.max
local findpos = s:find(t, 1, true)
local maxlength = 0
local mfl = math.floor
while findpos do
  if slen < findpos then
    break
  end
  local curlength = 1
  while true do
    local p = findpos + tlen * curlength
    if p < findpos + slen and t == s:sub(p, p + tlen - 1) then
      curlength = curlength + 1
    else
      break
    end
  end
  maxlength = mma(maxlength, curlength)
  if slen % tlen == 0 and curlength == mfl(slen / tlen) then
    maxlength = -1
    break
  end
  findpos = s:find(t, findpos + tlen * curlength, true)
end

local same_s, same_t = true, true
for i = 2, slen do if s:sub(1, 1) ~= s:sub(i, i) then same_s = false break end end
for i = 2, tlen do if t:sub(1, 1) ~= t:sub(i, i) then same_t = false break end end
if same_s and same_t and s:sub(1, 1) == t:sub(1, 1) then
  maxlength = -1
end
if swapped then
  if 0 < maxlength then
    maxlength = 0
  end
end
print(maxlength)
