#include <bits/stdc++.h>
int main() {
  long long a, c;
  long long y, g, b, ans = 0;
  long long couy = 0, coub = 0;
  scanf("%lld%lld", &a, &c);
  scanf("%lld%lld%lld", &y, &g, &b);
  couy += y * 2;
  couy += g;
  coub += g;
  coub += b * 3;
  if (couy - a > 0) ans = ans + couy - a;
  if (coub - c > 0) ans = ans + coub - c;
  printf("%lld", ans);
  return 0;
}
