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