#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, i, sum;
  scanf("%lld", &a);
  scanf("%lld", &b);
  long long int x[3];
  for (i = 0; i < 3; i++) {
    scanf("%lld", &x[i]);
  }
  long long int yellow, blue;
  yellow = x[0] * 2 + x[1];
  blue = x[1] + 3 * x[2];
  if (yellow <= a && blue <= b) {
    printf("0");
  } else if (yellow > a && blue < b) {
    printf("%lld", yellow - a);
  } else if (yellow < a && blue > b) {
    printf("%lld", blue - b);
  } else {
    printf("%lld", yellow - a + blue - b);
  }
}
