#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 1e6 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
const int CHARSET_SIZE = 26;
char s[MAXN],s2[MAXN],s3[MAXN];
int n;
struct Suffix_Automaton {
    int cnt, root, last, prt[MAXN << 1], son[MAXN << 1][CHARSET_SIZE], size[MAXN << 1],
        mx[MAXN << 1]; //root表示parent树的根/起始节点,prt表示的是当前匹配串的后缀
    int topo[MAXN << 1], buc[MAXN << 1]; //topo拓扑序 buc度数
    inline void init() {
        root = last = cnt = 1;
        size[cnt] = mx[cnt] = prt[cnt] = 0;
    }
    inline void extend(int c) //扩展SAM
    {
        int np = ++cnt, p = last; //np表示新的母串
        mx[np] = mx[p] + 1;
        size[np] = 1;
        for (; p && !son[p][c]; p = prt[p])
            son[p][c] = np; //将last的后缀连接路径上没有字符c出边的p连向np
        if (!p)                //如果p跳到了0 需要把np连向parent树的根
            prt[np] = root;
        else {
            int q = son[p][c];
            if (mx[q] == mx[p] + 1)
                prt[np] = q; //把u连接到trans(v,c)
            else //需要新建节点
            {
                int nq = ++cnt; //nq是new q是old
                memcpy(son[nq], son[q], sizeof(son[q])); //复制出边到新节点
                size[nq] = 0;
                mx[nq] = mx[p] + 1;
                prt[nq] = prt[q];      //nq的后缀链接指向q的后缀连接
                prt[q] = prt[np] = nq; //q和np的后缀链接指向nq
                for (; p && son[p][c] == q; p = prt[p])
                    son[p][c] = nq; //把路径上原来有转移的q的节点改成指向nq
            }
        }
        last = np; //替换整个母串
    }
    void toposort() //按照maxl从小到大排序
    {
        int maxv = 0;
        for (int i = 1; i <= cnt; i++)
        {
            buc[mx[i]]++;
            maxv = max(maxv, mx[i]);
        }
        for (int i = 1; i <= maxv; i++)
            buc[i] += buc[i - 1];
        for (int i = cnt; i >= 1; i--)
            topo[buc[mx[i]]--] = i;
    }
    void cal_right()
    {
        toposort();
        for (int i = cnt; i >= 1; i--) //递推right按照maxl从大到小
        {
            int v = topo[i];
            size[prt[v]] += size[v];
        }
    }
} sam;
int Next[MAXN];
void getnext(char *ch,int len){
    int i=0,j=-1;
    Next[0]=-1;
    while(i<len){
        if(j==-1 || ch[i]==ch[j]){
            i++;j++;
            Next[i]=j;
        }else
            j=Next[j];
    }
}
int main(){
    sam.init();
    scanf("%s",s);
    scanf("%s",s2);
    int l1=strlen(s);
    int l2=strlen(s2);
    int nw,cnt;
    for(int i0=1;i0<=2;i0++) {
        for (int i = 0; i < l2; i++) {
            sam.extend(s2[i] - 'a');
        }
    }
    nw=sam.root;
    cnt=0;
    while(cnt<l2){
        for(int i=0;i<26;i++){
            if(sam.son[nw][i]){
                nw=sam.son[nw][i];
                s3[cnt]='a'+i;
                cnt++;
                break;
            }
        }
    }
    sam.init();
    mem(sam.son,0);
    for(int i0=1;i0<=2;i0++) {
        for (int i = 0; i < l1; i++) {
            sam.extend(s[i] - 'a');
        }
    }
    nw=sam.root;
    cnt=0;
    while(cnt<l1){
        for(int i=0;i<26;i++){
            if(sam.son[nw][i]){
                nw=sam.son[nw][i];
                s[cnt]='a'+i;
                cnt++;
                break;
            }
        }
    }
    getnext(s,l1);
    int x1=l1-Next[l1];
    //printf("%d\n",x1);
    getnext(s3,l2);
    int x2=l2-Next[l2];
    int flag=0;
    if(x1!=x2)
        flag=1;
    else {
        for (int i = 0; i <x1;i++){
            if(s[i]==s3[i]){
                continue;
            }
            else{
                flag=1;
                break;
            }
        }
    }
    if(flag==0)
    {
        printf("-1\n");
        return 0;
    }
    nw=sam.root;
    int ans=0;
    sam.init();
    mem(sam.son,0);
    int t=l2/l1+(!!(l2%l1));
    for(int i=0;i<t+1;i++){
        for(int j=0;j<l1;j++){
            sam.extend(s[j]-'a');
        }
    }
    while(1) {
        for (int i = 0; i < l2; i++) {
            if (sam.son[nw][s2[i]-'a']){
                nw=sam.son[nw][s2[i]-'a'];
            }
            else{
                printf("%d\n",ans);
                return 0;
            }
        }
        ans++;
    }
}

Measured memory_bytes: 234240