# Original solution
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0

    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p-1]
                results.append((i-len(word), i))
                i -= 1
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
es = set()
d = [set() for _ in range(len(s)+1)]
d2 = [set() for _ in range(len(s)+1)]
#print(t, m*s)
#print(kmp_search(m*s, t))
for a, b in kmp_search(m*s, t):
    a, b = a%len(s)+1, b%len(s)+1
    es.add((a, b))
    d[a].add(b)
    d2[b].add(a)

#print(es)
fs = set()
r = 0
for x in range(len(s)+1):
    if x in fs:
        continue
    vs = set()
    vs.add(x)
    fs.add(x)
    depths = [inf]*(len(s)+1)
    depths[x] = 0
    stack = [x]
    mt = x
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt]:
                    mt = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    vs = set()
    vs.add(mt)
    depths = [inf]*(len(s)+1)
    depths[mt] = 0
    stack = [mt]
    mt2 = mt
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d2[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt2]:
                    mt2 = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    r = max(depths[mt2], r)
print((r if r != inf else -1))

# Optimized solution
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0

    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p-1]
                results.append((i-len(word), i))
                i -= 1
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
es = set()
d = [set() for _ in range(len(s)+1)]
d2 = [set() for _ in range(len(s)+1)]
#print(t, m*s)
#print(kmp_search(m*s, t))
for a, b in kmp_search(m*s, t):
    a, b = a%len(s)+1, b%len(s)+1
    es.add((a, b))
    d[a].add(b)
    d2[b].add(a)

#print(es)
fs = set()
r = 0
for x in range(len(s)+1):
    if x in fs:
        continue
    vs = set()
    vs.add(x)
    fs.add(x)
    depths = dict()
    depths[x] = 0
    stack = [x]
    mt = x
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt]:
                    mt = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    vs = set()
    vs.add(mt)
    depths = dict()
    depths[mt] = 0
    stack = [mt]
    mt2 = mt
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d2[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt2]:
                    mt2 = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    r = max(depths[mt2], r)
print((r if r != inf else -1))