using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int NN = (int)1e6;
		int MM = (int)1e6;
		var ca = new char[NN + MM];
		for(int i=0;i<NN;i++) ca[i] = S[i % S.Length];
		for(int i=0;i<MM;i++) ca[NN+i] = T[i % T.Length];
		
		N = S.Length;
		M = T.Length;
		var U = new String(ca);
//Console.WriteLine(U);
		var RH1 = new RollingHash(U,3241,(long)1e9 + 7);
		var RH2 = new RollingHash(U,5252,(long)1e9 + 9);
		
		bool[] Fit = new bool[N];
		var hash1 = RH1.GetHash(NN, M);
		var hash2 = RH2.GetHash(NN, M);
		for(int i=0;i<N;i++){
			var h1 = RH1.GetHash(i, M);
			var h2 = RH2.GetHash(i, M);
			if(h1 == hash1 && h2 == hash2) Fit[i] = true;
		}
		
		var UF = new UnionFind(N);
		for(int i=0;i<N;i++){
			int ni = (i + M) % N;
			if(Fit[i] && Fit[ni]) UF.Unite(i, ni);
		}
		
		int ma = 0;
		for(int i=0;i<N;i++){
			if(!Fit[i]) continue;
			int cnt = UF.MemCnt(i);
			if( (long) cnt * (long) M % (long) N == 0){
				Console.WriteLine(-1);
				return;
			}
			ma = Math.Max(ma, cnt);
		}
		
		Console.WriteLine(ma);
		
		
	}
	int N;
	int M;
	
	String S;
	String T;
	public Sol(){
		S = rs();
		T = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


// 2つ以上のRHで確認する時はGetHashの積かなにかをつかう（xor，pairはダメ!!!）
class RollingHash{
	
	long[] Hash;
	long[] Base;
	long[] BaseInv;
	String S;
	long mod;
	int N;
	
	public RollingHash(String s_,long base_=2525,long mod_=(long)1e9+7){
		mod=mod_;
		S=s_;
		N=S.Length;
		Hash=new long[N+1];
		
		Base=new long[N+1];
		Base[0]=1;
		Base[1]=base_;
		
		BaseInv=new long[N+1];
		BaseInv[0]=1;
		BaseInv[1]=ModInv(Base[1]);
	
		for(int i=1;i<N;i++){
			Base[i+1]=Base[i]*Base[1];
			if(Base[i+1]>=mod)Base[i+1]%=mod;
			BaseInv[i+1]=BaseInv[i]*BaseInv[1];
			if(BaseInv[i+1]>=mod)BaseInv[i+1]%=mod;
		}
		
		Hash[0]=0;
		Hash[1]=(long)S[0];
		for(int i=1;i<N;i++){
			Hash[i+1]=Hash[i]*Base[1]+(long)S[i];
			if(Hash[i+1]>=mod)Hash[i+1]%=mod;
		}
//for(int i=0;i<=N;i++)Console.WriteLine("{0}:{1}",i,Hash[i]);
	}
	
	public long GetHash(int strt,int len){
		//return hash of S.Substring(strt,len);
		if(len==0)return 0;
		if(strt+len>=N)len=N-strt;
		long ret=Hash[strt+len]+mod-(Hash[strt]*Base[len]>=mod?Hash[strt]*Base[len]%mod:Hash[strt]*Base[len]);
		return ret>=mod?ret%mod:ret;
	}
	
	
	
	
	public long ModInv(long x){
		//Mod-Inverse of x by Ext-Euclid
		// solve (x,mod)-->(a,b,c) s.t. a * x + b * mod = c 
		//  if(x==0 || c!=1) return 0;
		//  return a (since a * x == 1 modulo mod)
		long a=0,b=0,c=0;
		if(x==0)return 0;
		ExtGCD(x,mod,ref a,ref b,ref c);
		if(c!=1)return 0;
		return (a+mod)%mod;
	}
	
	public static void ExtGCD(long x,long y,ref long a,ref long b,ref long c){
		long r0=x;long r1=y;
		long a0=1;long a1=0;
		long b0=0;long b1=1;
		long q1,r2,a2,b2;
		while(r1>0){
			q1=r0/r1;
			r2=r0%r1;
			a2=a0-q1*a1;
			b2=b0-q1*b1;
			r0=r1;r1=r2;
			a0=a1;a1=a2;
			b0=b1;b1=b2;
		}
		c=r0;
		a=a0;
		b=b0;
	}
}

class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public UnionFind(int n_){
		Initialize(n_);
	}
	
	public void Initialize(int n_){
		N=n_;
		parent=new int[N];
		mem=new int[N];
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo=N;
	}
	
	public int Parent(int a){
		if(parent[a]==a) return a;
		return parent[a] = Parent(parent[a]);
	}
	
	public bool IsUnited(int a,int b){
		return Parent(a) == Parent(b);
	}
	
	public void Unite(int a,int b){
		a = Parent(a); b = Parent(b);//Parent()を呼ぶことでa以上のノードは全てparentがrootになる
		if(a == b) return;
		parent[a] = b;
		mem[b] += mem[a];
		compo -= 1;
	}
	
	public bool IsRoot(int x){
		return x == parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		for(int i=0;i<parent.Length;i++){
			Console.Write(i==0?"{0}":" {0}",parent[i]);
		}
		Console.WriteLine("");
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


Measured memory_bytes: 142352