#include <iostream>
#include <vector>

int solve(std::vector<int> &V) {
    const int MAX = 30;
    const int INF = 100;
    int ans = INF;
    for (int A = 1; A <= MAX; A++) {
        for (int B = A + 1; B <= MAX; B++) {
            for (int C = B + 1; C <= MAX; C++) {
                std::vector<int> dp(MAX + 1, INF);
                dp.at(0) = 0;
                for (int i = 0; i < MAX; i++) {
                    int y = dp.at(i) + 1;
                    for (const auto &x: {A, B, C}) {
                        if (i + x <= MAX && dp.at(i + x) > y) {
                            dp.at(i + x) = y;
                        }
                    }
                }
                int tmp = 0;
                for (const auto &v: V) {
                    if (dp.at(v) == INF) {
                        tmp = INF;
                    } else {
                        tmp += dp.at(v);
                    }
                }
                if (ans > tmp) { ans = tmp; }
            }
        }
    }
    return (ans != INF ? ans : -1);
}

int main() {
    std::vector<int> V(4);
    for (int i = 0; i < 4; i++) { std::cin >> V.at(i); }
    std::cout << solve(V) << std::endl;
}