#include <iostream>
#include "stdio.h"
#include "stdlib.h"

using namespace std;

int main()
{
   freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

   int L, d, a, N, W;
   cin >> L >> d >> a >> N >> W;
   for (int x = 0; x < L+d; x++) {
      int ok = 1;
      for (int i = 0; i < N; i++) {
         int xx = x+W*i - a, yy = x+W*(i+1) - L - a;
         int v = yy / (L+d);
         if (yy < 0 && (-yy) % (L+d)) v--;
         int u = xx / (L+d);
         if (xx >= 0 && xx % (L+d)) u++;
         if (u < 0) u = 0;
         if (u > v || u != v) {ok = 0; break;}
      }   
      if (ok) {cout << x; break;}
   }

   fclose(stdin); fclose(stdout);
   return 0;
}
