#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
// int
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

/*
vector<int> suffix_array(string const & s) {
	int n = SI(s);
	vector<int> r(n + 1), a(n + 1);
	inc(i, n + 1) {
		r[i] = (i < n ? s[i] : 0);
		a[i] = i;
	}
	for(int k = 1; k < n; k <<= 1) {
		auto comp = [&](int x, int y) -> bool {
			int xa = r[x], xb = r[min(x + k, n)];
			int ya = r[y], yb = r[min(y + k, n)];
			return (MP(xa, xb) < MP(ya, yb));
		};
		sort(ALL(a), comp);
		int c = 0;
		vector<int> rr(n + 1);
		inc(i, n) { rr[a[i + 1]] = rr[a[i]] + (comp(a[i], a[i + 1]) ? 1 : 0); }
		r = rr;
	}
	return a;
}

vector<int> lcp_array(string const & s, vector<int> const & SA) {
	int n = SI(s);
	vector<int> r(n + 1), l(n + 1); // l[i] = lcp(s.substr(SA[i]), s.substr(SA[i + 1])), l[n] = 0
	inc(i, n + 1) { r[SA[i]] = i; }
	int c = 0;
	inc(i, n) {
		if(c > 0) { c--; }
		int j = SA[r[i] - 1];
		while(max(i, j) + c < n && s[i + c] == s[j + c]) { c++; }
		l[r[i] - 1] = c;
	}
	return l;
}
*/

vector<int> rotation_array(string const & s) {
	int n = SI(s);
	vector<int> r(n), a(n);
	inc(i, n) {
		r[i] = s[i];
		a[i] = i;
	}
	for(int k = 1; k < n; k <<= 1) {
		auto comp = [&](int x, int y) -> bool {
			int x1 = r[x], x2 = r[x + k - (x + k < n ? 0 : n)];
			int y1 = r[y], y2 = r[y + k - (y + k < n ? 0 : n)];
			return (MP(x1, x2) < MP(y1, y2));
		};
		stable_sort(ALL(a), comp);
		vector<int> rr(n);
		inc(i, n - 1) { rr[a[i + 1]] = rr[a[i]] + (comp(a[i], a[i + 1]) ? 1 : 0); }
		r = rr;
	}
	return a;
}

vector<int> rotation_lcp_array(string const & s, vector<int> const & RA) {
	int n = SI(s);
	vector<int> r(n), l(n); // l.back() == 0
	inc(i, n) { r[RA[i]] = i; }
	int c = 0;
	inc(i, n) {
		if(c > 0) { c--; }
		if(r[i] + 1 == n) { continue; }
		int j = RA[r[i] + 1];
		while(c < n && s[(i + c) % n] == s[(j + c) % n]) { c++; }
		l[r[i]] = c;
		if(j + 1 == n) { c = 0; }
	}
	return l;
}


/*
vector<int> suffix_array_test(string const & s) {
	int n = SI(s);
	vector<pair<string, int>> v;
	inc(i, n + 1) { v.EB(s.substr(i), i); }
	sort(ALL(v));
	
	vector<int> r(n + 1);
	inc(i, n + 1) { r[i] = v[i].SE; }
	return r;
}
vector<int> lcp_array_test(string const & s, vector<int> const & sa) {
	int n = SI(s);
	vector<int> l(n + 1);
	inc(i, n) {
		int j = 0;
		while(max(sa[i], sa[i + 1]) + j < n && s[sa[i] + j] == s[sa[i + 1] + j]) { j++; }
		l[i] = j;
	}
	return l;
}
vector<int> rotation_array_test(string const & s) {
	int n = SI(s);
	vector<pair<string, int>> v;
	inc(i, n) { v.EB((s + s).substr(i, n), i); }
	sort(ALL(v));
	
	vector<int> a(n);
	inc(i, n) { a[i] = v[i].SE; }
	return a;
}
vector<int> rotation_lcp_array_test(string const & s, vector<int> const & a) {
	int n = SI(s);
	vector<int> l(n);
	inc(i, n - 1) {
		int c = 0;
		while(c < n && s[(a[i] + c) % n] == s[(a[i + 1] + c) % n]) { c++; }
		l[i] = c;
	}
	return l;
}
template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "["; inc(i, SI(v)) { os << (i == 0 ? "" : ", ") << v[i]; } os << "]";
	return os;
}
int test() {
	string s;
	cin >> s;
	cout << s << endl;
	
	auto sa1 = suffix_array     (s); cout << sa1 << endl;
	auto sa2 = suffix_array_test(s); cout << sa2 << endl;
	assert(sa1 == sa2);
	auto s_lcp1 = lcp_array     (s, sa1); cout << s_lcp1 << endl;
	auto s_lcp2 = lcp_array_test(s, sa2); cout << s_lcp2 << endl;
	assert(s_lcp1 == s_lcp2);
	
	auto ra1 = rotation_array     (s); cout << ra1 << endl;
	auto ra2 = rotation_array_test(s); cout << ra2 << endl;
	assert(ra1 == ra2);
	auto r_lcp1 = rotation_lcp_array     (s, ra1); cout << r_lcp1 << endl;
	auto r_lcp2 = rotation_lcp_array_test(s, ra2); cout << r_lcp2 << endl;
	assert(r_lcp1 == r_lcp2);
	
	return 0;
}
*/

int main() {
	string s, t;
	cin >> s >> t;
	
	auto ra = rotation_array(s);
	auto lcp = rotation_lcp_array(s, ra);
	
	int n = SI(s), m = SI(t), c = 0;
	inc(i, SI(ra)) {
		while(c < n + m && s[(ra[i] + c) % n] == t[c % m]) { c++; }
		if(lcp[i] < c) { break; }
	}
	
	cout << (c == n + m ? -1 : c / m) << endl;
	
	return 0;
}


Measured memory_bytes: 9140