#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y, z, sum;
  scanf("%lld", &a);
  scanf("%lld", &b);
  scanf("%lld", &x);
  scanf("%lld", &y);
  scanf("%lld", &z);
  x = x * 2;
  x = x + y;
  z = z * 3;
  z = z + y;
  long long ye = x - a;
  if (ye < 0) ye = 0;
  long long bl = z - b;
  if (bl < 0) bl = 0;
  printf("%lld", ye + bl);
}
