#include<iostream>
#include<string>
// Need start
#include<vector>
#include<functional>
// Need end
using namespace std;

// Copy start
template<typename T>
class KMP {
    private:
        std::vector<T> pattern_;
        std::vector<int> shift_table_;
    public:
        KMP(const std::vector<T>& pattern):pattern_(pattern) {
            // calculate tagged border
            int pattern_size = (int)pattern_.size();
            std::vector<int> tagged_border(pattern_size + 1);
            tagged_border[0] = -1;  // -1 means there is no border
            int prev_border = -1;
            for (int i = 0; i < pattern_size; ++i) {
                while (prev_border >= 0 && pattern_[prev_border] != pattern_[i]) {
                    prev_border = tagged_border[prev_border];
                }
                ++prev_border;
                if (i + 1 < pattern_size && pattern_[i + 1] == pattern_[prev_border]) {
                    tagged_border[i + 1] = tagged_border[prev_border];
                }
                else tagged_border[i + 1] = prev_border;
            }
            shift_table_ = tagged_border;
        }
        std::vector<int> getShiftTable() {
            return shift_table_;
        }
        std::vector<int> search(const std::vector<T>& target, std::function<bool(T, T)> is_same=[](T a, T b) {return a == b;}) {
            if (target.size() < pattern_.size()) {
                return std::vector<int>();
            }
            // return matching position
            std::vector<int> res;
            int target_size = (int)target.size(), pattern_size = (int)pattern_.size();
            int target_ptr = 0, pattern_ptr = 0;
            while (target_ptr < target_size) {
                if (is_same(target[target_ptr], pattern_[pattern_ptr])) {
                    ++target_ptr;
                    ++pattern_ptr;
                }
                else {
                    if (pattern_ptr == 0) {
                        ++target_ptr;
                    }
                    else {
                        if (shift_table_[pattern_ptr] < 0) {
                            pattern_ptr = 0;
                        }
                        else {
                            pattern_ptr = shift_table_[pattern_ptr];
                        }
                    }
                }
                if (pattern_ptr == pattern_size) {
                    res.push_back(target_ptr - pattern_ptr);
                    if (shift_table_[pattern_ptr] < 0) {
                        pattern_ptr = 0;
                    }
                    else {
                        pattern_ptr = shift_table_[pattern_ptr];
                    }
                }
            }
            return res;
        }
};
// Copy end

int N, M;

const int MAX_LEN = 2020202;

bool is_ok[MAX_LEN], is_visited[MAX_LEN];
int period[MAX_LEN];

void dfs(int idx) {
    is_visited[idx] = true;
    period[idx] = -1;
    int next_idx = (idx + M) % N;
    if (!is_ok[next_idx]) {
        period[idx] = 1;
        return;
    }
    if (is_visited[next_idx]) {
        if (period[next_idx] < 0) {
            period[idx] = -1;
            return;
        }
        else {
            period[idx] = period[next_idx] + 1;
            return;
        }
    }
    dfs(next_idx);
    if (period[next_idx] >= 0) period[idx] = period[next_idx] + 1;
}

int main() {
    // This sample is Atcode Beginners Contest 135 F
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    M = T.size();
    string SS = S;
    while (SS.size() < T.size()) {
        SS += S;
    }
    N = SS.size();
    KMP<char> kmp(vector<char>(T.begin(), T.end()));
    string SSS = SS + SS;
    vector<int> result = kmp.search(vector<char>(SSS.begin(), SSS.end()));
    for (int i = 0; i < (int)result.size(); ++i) {
        is_ok[result[i]] = true;
    }
    for (int i = 0; i < N; ++i) {
        if (is_ok[i] && !is_visited[i]) dfs(i);
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (period[i] < 0) {
            cout << -1 << endl;
            return 0;
        }
        ans = max(period[i], ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 43504