#include <bits/stdc++.h>
using namespace std;
long long x, y, z, a, b;
int main() {
  cin >> a >> b >> x >> y >> z;
  long long aa = 2ll * x + 1ll * y;
  long long bb = 1ll * y + 3ll * z;
  printf("%lld\n", max(0ll, aa - a) + max(0ll, bb - b));
  return 0;
}
