
var
  L, d, a, N, W: Integer;

  function Check(f, c: Integer): Boolean;
  var
    j: Integer;
  begin
    Result := false;
    for j := 1 to N do begin
      while f < c do Inc(f, L + d);
      if f + L > c + W then exit;
      Inc(f, L + d);
      if f + L <= c + W then exit;
      Inc(c, W);
    end;
    Result := true;
  end;

var
  f: TextFIle;
  x: Integer;
begin
  AssignFile(f, 'input.txt'); Reset(f);
  Read(f, L, d, a, N, W);
  CloseFile(f);

  for x := 0 to L + d - 1 do
    if Check(a, x) then break;

  AssignFile(f, 'output.txt'); Rewrite(f);
  Writeln(f, x);
  CloseFile(f);
end.
