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