#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
long long int vis[N];
long long int steps[N];
long long int dca, dcc, dla, dlc;
long long int start;
long long int a, b, w, x, c;
long long int SCALE = 100000000000000;
void dfs(long long int val, long long int d, long long int s) {
  vis[val] = d;
  steps[val] = s;
  long long int nval;
  if (val >= x) {
    nval = val - x;
    s++;
  } else {
    nval = w - (x - val);
    d++;
    s++;
  }
  if (vis[nval]) {
    dca = d - vis[nval];
    dcc = s - steps[nval];
    dla = vis[nval] - 1;
    dlc = steps[nval] - 1;
    start = nval;
    return;
  }
  dfs(nval, d, s);
}
long long int dfs1(long long int d, long long int cur) {
  if (!d) return 0;
  if (cur >= x)
    return dfs1(d - 1, cur - x);
  else
    return 1 + dfs1(d - 1, w - (x - cur));
}
long long int solve(long long int mi) {
  long long int d = c - mi;
  long long int ad = 0;
  if (dlc >= d) {
    ad = dfs1(d, b);
  } else {
    d -= dlc;
    ad += dla;
    long long int tmp = d / dcc;
    d -= tmp * dcc;
    ad += tmp * dca;
    ad += dfs1(d, start);
  }
  return a - ad;
}
int main() {
  cin >> a >> b >> w >> x >> c;
  if (c <= a) {
    printf("0\n");
    return 0;
  }
  c += SCALE;
  a += SCALE;
  dfs(b, 1, 1);
  long long int lo = 0;
  long long int hi = c;
  long long int ans = 0;
  while (lo <= hi) {
    long long int mi = (lo + hi) >> 1;
    long long int x = solve(mi);
    if (mi <= x) {
      ans = mi;
      lo = mi + 1;
    } else {
      hi = mi - 1;
    }
  }
  cout << c - ans << endl;
  return 0;
}
