#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000009
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<complex<double>>  DFT(vector<complex<double>> a) {
	int n = a.size();
	if (n == 1) return a;
	vector<complex<double>> a0(n / 2), a1(n / 2);
	REP(i, n) {
		if (i % 2 == 0) {
			a0[i / 2] = a[i];
		}
		else {
			a1[i / 2] = a[i];
		}
	}
	vector<complex<double>> inversed_a0 = DFT(a0), inversed_a1 = DFT(a1);
	vector<complex<double>> inversed_a(n);
	for (int i = 0; i < n; ++i) {
		complex<double> zeta = complex<double>(cos(2 * Ma_PI * i / n), sin(2 * Ma_PI * i / n));
		inversed_a[i] = inversed_a0[i % (n / 2)] + zeta * inversed_a1[i % (n / 2)];
	}
	return inversed_a;
}
vector<complex<double>> IDFT(vector<complex<double>> inversed_a) {
	int n = inversed_a.size();
	vector<complex<double>> now = DFT(inversed_a);
	reverse(now.begin(), now.end());
	for (int q = now.size() - 1; q >= 1; --q) {
		swap(now[q], now[q - 1]);
	}
	REP(i, n) {
		now[i] /= complex<double>(n, 0);
	}
	return now;
}
vector<complex<double>> conv(vector<complex<double>> a, vector<complex<double>> b) {
	int deg = a.size() + b.size() - 1;
	int n = 1;
	while (n < deg) n <<= 1;
	a.resize(n);
	b.resize(n);
	vector<complex<double>> inversed_a = DFT(a), inversed_b = DFT(b);
	vector<complex<double>> inversed_c(n);
	REP(i, n) {
		inversed_c[i] = inversed_a[i] * inversed_b[i];
	}
	return IDFT(inversed_c);
}
long long powing(long long now, long long hoge) {
	long long ans = 1;
	while (hoge != 0) {
		if (hoge % 2 == 1) {
			ans *= now;
			ans %= MOD;
		}
		hoge /= 2;
		now *= now;
		now %= MOD;
	}
	return ans;
}
long long inv(long long now) {
	return powing(now, MAX_MOD - 2LL);
}
unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x^(x << 11));
	x = y; y = z; z = w;
	return (w = (w^(w >> 19))^(t^(t >> 8)));
}
long long dp[10000000];
string a, b;
int main() {
#define int long long
	cin >> a >> b;
	int changed = 0;
	for (int i = 1; i < a.length(); ++i) {
		if (a[i] != a[i - 1]) {
			changed = 1;
			break;
		}
	}
	for (int i = 1; i < b.length(); ++i) {
		if (b[i] != b[i - 1]) {
			changed = 1;
			break;
		}
	}
	if (changed == 0) {
		if (a[0] == b[0]) {
			cout << -1 << endl;
			return 0;
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}
	a += a;
	a += a;
	while (a.length() <= b.length() * 4LL) {
		a += a;
	}
	long long sum_A = 0;
	long long sum_B = 0;
	for (int i = b.length() - 1; i >= 0; --i) {
		sum_A *= 26LL;
		sum_B *= 26LL;
		sum_A += b[i] - 'a';
		sum_B += b[i] - 'a';
		sum_A %= MAX_MOD;
		sum_B %= MOD;
	}
	long long now_Sum_A = 0;
	long long now_Sum_B = 0;
	long long back_itr_A = 1;
	long long back_itr_B = 1;
	for (int i = a.length() - 1; i >= 0; --i) {
		now_Sum_A *= 26LL;
		now_Sum_B *= 26LL;
		now_Sum_A += a[i] - 'a';
		now_Sum_B += a[i] - 'a';
		now_Sum_A %= MAX_MOD;
		now_Sum_B %= MOD;
		int nexter = i + b.length();
		if (nexter < a.length()) {
			now_Sum_A -= ((a[nexter] - 'a') * back_itr_A) % MAX_MOD;
			now_Sum_B -= ((a[nexter] - 'a') * back_itr_B) % MOD;
			now_Sum_A += 3LL * MAX_MOD;
			now_Sum_B += 3LL * MOD;
			now_Sum_A %= MAX_MOD;
			now_Sum_B %= MOD;
		}
		else {
			back_itr_A *= 26LL;
			back_itr_B *= 26LL;
			back_itr_A %= MAX_MOD;
			back_itr_B %= MOD;
		}
		if (nexter <= a.length()) {
			if (now_Sum_A == sum_A && now_Sum_B == sum_B) {
				dp[i] = dp[nexter] + 1;
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i <= a.length(); ++i) {
		ans = max(ans, dp[i]);
	}
	long long hoge = a.length();
	hoge /= 2LL;
	hoge /= b.length();
	if (ans > hoge) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 35348