#include <bits/stdc++.h>

int main() {
    freopen("numbers.in", "r", stdin);
    freopen("numbers.out", "w", stdout);
    std::vector <int> a(4);
    for (int i = 0; i < 4; i++)
        scanf("%d", &a[i]);
    std::vector <int> answer;
    for (int power = 1; power <= 3; power++) {
        int res = 0;
        for (int i = 0; i < 3; i++) {
            int add = 1;
            for (int j = 0; j < power; j++)
                add *= a[i];
            res += add;
        }
        if (res == a[3])
            answer.push_back(power);
    }
    if ((int)answer.size() != 1) {
        printf("-1\n");
    } else {
        printf("%d\n", answer.back());
    }
    return 0;
}
