#include <bits/stdc++.h>
using namespace std;
#define Long long long
#define int long long

map<pair<Long, Long>, Long> memo2;
Long modpow(Long a, Long n, Long mod) {
    if (memo2.count({a, n})) return memo2[{a, n}];
    if (n == 0) return 1;
    if (n % 2 == 0) {
        Long t = modpow(a, n / 2, mod);
        return memo2[{a, n}] = t * t % mod;
    }
    return memo2[{a, n}] = a * modpow(a, n - 1, mod) % mod;
}

map<pair<Long, Long>, Long> memo;
// a^0 + a^1 + ... + a^{n-1}
Long powsum(Long a, Long n, Long mod) {
    if (memo.count({a, n})) return memo[{a, n}];
    if (n == 0) return 0;
    if (n % 2 == 0) {
        Long t = powsum(a, n / 2, mod);
        return memo[{a, n}] = (1 + modpow(a, n / 2, mod)) * t % mod;
    }
    return memo[{a, n}] = (modpow(a, n - 1, mod) + powsum(a, n - 1, mod)) % mod;
}

template <Long mod, Long p = 257>
struct RollingHash {
    int n;
    vector<Long> table;
    vector<Long> pows;
    RollingHash(const string &s) : n(s.size()), table(n + 1), pows(n + 1) {
        pows[0] = 1;
        for (int i = 0; i < n; i++) {
            table[i + 1] = (table[i] * p + s[i]) % mod;
            pows[i + 1] = pows[i] * p % mod;
        }
    }

    // 配列外参照用
    Long get_table(long long r) {
        if (r <= n) return table[r];
        Long ret = powsum(pows[n], r / n, mod) * table[n] % mod;
        r %= n;
        ret = (ret * pows[r] + table[r]) % mod;
        return ret;
    }

    Long get_pow(long long r) {
        if (r <= n) return pows[r];
        return modpow(p, r, mod);
    }

    // [l, r)
    Long hash_substr(long long l, long long r) {
        Long ret = (get_table(r) - get_table(l) * get_pow(r - l)) % mod;
        if (ret < 0) ret += mod;
        return ret;
    }
};

using RH = RollingHash<((Long)1 << 31) - 1>;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    auto start = chrono::steady_clock::now();

    string s, t;
    cin >> s >> t;

    RH rhs(s), rht(t);

    int tlen = t.size();
    int ans = 0;
    vector<int> ind(s.size());
    iota(ind.begin(), ind.end(), 0);
    random_device rnd;
    shuffle(ind.begin(), ind.end(), rnd);
    bool updated = false;
    Long thash = 0;
    for (int i : ind) {
        auto now = chrono::steady_clock::now();
        if (chrono::duration_cast<chrono::milliseconds>(now - start).count() > 1995) {
            cout << ans << endl;
            return 0;
        }
        if (ans == 0 && s[i] != t[0]) continue;
        if (updated) thash = rht.hash_substr(0, (long long)ans * tlen);
        updated = false;
        if (rhs.hash_substr(i, i + (long long)ans * tlen) != thash) continue;
        thash = rht.hash_substr(0, (long long)1e9 * tlen);
        if (rhs.hash_substr(i, i + (long long)1e9 * tlen) == thash) {
            cout << -1 << endl;
            return 0;
        }
        int l = ans, r = 1e9;
        while (l < r - 1) {
            int m = (l + r) / 2;
            long long len = (long long)m * tlen;
            thash = rht.hash_substr(0, len);
            if (rhs.hash_substr(i, i + len) == thash) {
                l = m;
            } else {
                r = m;
            }
        }
        ans = l;
        updated = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 23324