let readString () = Scanf.scanf " %s" (fun s -> s)

let borders s =
  let n = String.length s in
  let b = Array.make (n+1) (-1) in
  for i=0 to n-1 do
    let j = ref b.(i) in
    while !j >= 0 && s.[!j] <> s.[i] do
      j := b.(!j)
    done;
    b.(i+1) <- !j+1
  done;
  b

type result = [`Unknown | `Cycle | `Length of int]
type knownResult = [`Cycle | `Length of int]

let rec compare (a: result) (b: result) =
  match (a, b) with
  | (`Unknown, `Unknown) -> 0
  | (`Cycle, `Cycle) -> 0
  | (`Length x, `Length y) -> Pervasives.compare x y
  | (`Unknown, _) -> -1
  | (`Cycle, _) -> 1
  | _ -> -(compare b a)

let solve s t : knownResult =
  let n = String.length s in
  let m = String.length t in
  let b = borders t in
  let yes = Array.make n false in
  let j = ref 0 in
  for i=0 to n+m-2 do
    while !j >= 0 && (!j >= m || t.[!j] <> s.[i mod n]) do
      j := b.(!j)
    done;
    incr j;
    if !j = m then yes.(i+1-m) <- true
  done;
  let plen: result array = Array.make n `Unknown in
  let rec calc ?(start = None) i : knownResult =
    let i0 = match start with None -> i | Some i0 -> i0 in
    match plen.(i) with
    | `Unknown ->
        begin
          let ans =
            if start <> None && i = i0 then `Cycle
            else if not yes.(i) then `Length 0
            else
              match calc ~start:(Some i0) ((i + m) mod n) with
              | `Cycle -> `Cycle
              | `Length x -> `Length (1 + x)
          in
          plen.(i) <- ans;
          ans
        end
    | `Cycle -> `Cycle
    | `Length x -> `Length x
  in
  let res: knownResult ref = ref (`Length 0) in
  for i=0 to n-1 do
    let x = calc i in
    if compare (!res :> result) (x :> result) < 0 then res := x
  done;
  match !res with
  | `Cycle -> `Cycle
  | `Length x -> `Length x

let main () =
  let s = readString () in
  let t = readString () in
  Printf.printf "%d\n" (match solve s t with `Cycle -> -1 | `Length x -> x)

let () = main ()
