#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

vector<size_t> kmp_multi_match(const string& doc, const string& pat) {
    vector<size_t> matches;
    if (pat.empty()) {
        return matches;
    }
    vector<ptrdiff_t> next(pat.size() + 1);
    next[0] = -1;
    for (size_t i = 1; i <= pat.size(); ++i) {
        ptrdiff_t pos = next[i - 1];
        while(pos >= 0 && pat[i - 1] != pat[pos]) {
            pos = next[pos];
        }
        next[i] = pos + 1;
    }

    ptrdiff_t pos = 0;
    for (size_t i = 0; i < doc.size();) {
        while(pos >= 0 && (pos == pat.size() || pat[pos] != doc[i])) {
            pos = next[pos];
        }
        ++pos;
        ++i;
        if (pos == pat.size()) {
            matches.emplace_back(i - pat.size());
        }
    }
    return matches;
}

pair<vector<int>, vector<int>> topo_sort(int N, const vector<pair<int, int>>& edges) {
    vector<vector<int>> adj(N);
    vector<int> indegree(N);
    for (const auto& e : edges) {
        adj[e.first].emplace_back(e.second);
        indegree[e.second] += 1;
    }
    deque<int> q;
    vector<int> topo_seq;
    vector<int> layer_sizes;
    for (int i = 0; i < N; ++i) {
        if (indegree[i] == 0) {
            q.emplace_back(i);
        }
    }
    while(!q.empty()) {
        int lsiz = q.size();
        layer_sizes.emplace_back(lsiz);
        sort(q.begin(), q.end());
        for (int i = 0; i < lsiz; ++i) {
            int cur_node = q.front();
            topo_seq.emplace_back(cur_node);
            q.pop_front();
            for (int next_node : adj[cur_node]) {
                indegree[next_node] -= 1;
                if (indegree[next_node] == 0) {
                    q.emplace_back(next_node);
                }
            }
        }
    }
    if (topo_seq.size() != N) {
        topo_seq.clear();
        layer_sizes.clear();
    }
    return make_pair(move(topo_seq), move(layer_sizes));
}

class Solution {
public:
    int string_of_eternity(const string& s, const string& t) {
        string exs(s.size() + t.size() - 1, '\0');
        for (size_t i = 0; i < exs.size(); ++i) {
            exs[i] = s[i % s.size()];
        }
        LOG("Expanded s: {}\n", exs);
        auto matches = kmp_multi_match(exs, t);
        LOG("Number of matches: {}\n", matches.size());
        vector<pair<int, int>> edges;
        for (auto m : matches) {
            edges.emplace_back(m, (m + t.size()) % s.size());
        }
        auto topo_result = topo_sort(s.size(), edges);
        if (topo_result.second.empty()) {
            return -1;
        } else {
            return topo_result.second.size() - 1;
        }
    }
private:

};

int solve() {
    Solution solution;
    // handle IO here
    string s;
    string t;
    getline(cin, s);
    getline(cin, t);
    cout << solution.string_of_eternity(s, t) << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 44944