#include <stdio.h>

int mod(int a, int b)
{
    if (a >= 0)
        return a%b;
    else {
        int c = b - (-a)%b;
        if (c == b)
            c = 0;
        return c;
    }
}

int main()
{
    FILE* fin = fopen("input.txt", "r");
    FILE* fout = fopen("output.txt", "w");

    int L, d, a, N, W;
    int x;

    fscanf(fin, "%d%d%d%d%d", &L, &d, &a, &N, &W);

    for (x = 0; x < L+d; ++x) {
        int i;
        int flag = 1;
        for (i = 1; i <= N; ++i) {
            if (!(
            W-2*L-d < mod(a-x-(i-1)*W, L+d) &&
            mod(a-x-(i-1)*W, L+d) <= W-L)) {
                flag = 0;
                break;
            }
        }
        if (flag) {
            fprintf(fout, "%d", x);
            break;
        }
    }

    fclose(fin);
    fclose(fout);

    return 0;
}
