macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashMap;

fn main() {
    input!{
        s: chars,
        t: chars
    }
    let sl = s.len();
    let tl = t.len();
    let s: Vec<char> = s.iter().cycle().take(sl + tl - 1).map(|x| *x).collect();
    let mut m = vec![false; sl];
    kmp(&s, &t, &mut m);
    let mut smap: HashMap<usize, ((usize, usize), usize)> = HashMap::new();
    let mut emap: HashMap<usize, ((usize, usize), usize)> = HashMap::new();
    let mut ans: usize = 0;
    for i in 0..sl {
        if m[i] {
            let j = (i + tl) % sl;
            if i == j {
                println!("-1");
                return;
            }
            if let Some(&((ss, _i), l1)) = emap.get(&i) {
                if let Some(&((_j, tt), l2)) = smap.get(&j) {
                    if ss == j && tt == i {
                        println!("-1");
                        return;
                    }
                    smap.remove(&j);
                    emap.remove(&i);
                    smap.insert(ss, ((ss, tt), l1 + l2 + 1));
                    emap.insert(tt, ((ss, tt), l1 + l2 + 1));
                    ans = max(ans, l1 + l2 + 1);
                } else {
                    emap.remove(&i);
                    smap.insert(ss, ((ss, j), l1 + 1));
                    emap.insert(j, ((ss, j), l1 + 1));
                    ans = max(ans, l1 + 1);
                }
            } else {
                if let Some(&((_j, tt), l2)) = smap.get(&j) {
                    smap.remove(&j);
                    smap.insert(i, ((i, tt), l2 + 1));
                    emap.insert(tt, ((i, tt), l2 + 1));
                    ans = max(ans, l2 + 1);
                } else {
                    smap.insert(i, ((i, j), 1));
                    emap.insert(j, ((i, j), 1));
                    ans = max(ans, 1);
                }
            }
        }
    }
    println!("{}", ans);
}

fn kmp(s: &[char], sub: &[char], mat: &mut [bool]) {
    let m = sub.len();
    let mut tab: Vec<usize> = vec![0; m + 1];
    let mut i = 2;
    let mut j = 0;
    while i <= m {
        if sub[i - 1] == sub[j] {
            tab[i] = j + 1;
            i += 1;
            j += 1;
        } else if j > 0 {
            j = tab[j];
        } else {
            i += 1;
        }
    }
    i = 0;
    j = 0;
    while i + j < s.len() {
        if sub[j] == s[i + j] {
            j += 1;
            if j == m {
                mat[i] = true;
                i += j - tab[j];
                j = tab[j];
            }
        } else {
            if j == 0 {
                i += 1;
            } else {
                i += j - tab[j];
                j = tab[j];
            }
        }
    }
}


Measured memory_bytes: 22912