#include <stdio.h>

int nums[4];

int is_arith() {
    int diff = nums[1] - nums[0];
    for (int i = 1; i < 4; ++i) {
        if (nums[i] != nums[i-1] + diff)
            return 0;
    }
    return 1;
}

int is_geo() {
    int diff = nums[1] / nums[0];
    for (int i = 1; i < 4; ++i) {
        if (nums[i] != nums[i-1] * diff)
            return 0;
    }
    return 1;
}

int main() {
    while (1) {
        scanf("%d %d %d %d", &nums[0], &nums[1], &nums[2], &nums[3]);
        if (nums[0] == -1 && nums[1] == -1)
            break;

        // find missing number
        int i;
        for (i = 0; nums[i] != -1; ++i);

        // try all possibilities!
        int ans = -1;
        for (nums[i] = 1; nums[i] <= 10000; ++nums[i]) {
            if (is_arith() || is_geo()) {
                ans = nums[i];
                break;
            }
        }

        printf("%d\n", ans);
    }
}