#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
long long gcd(long long x, long long y) {
  return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long lcm(long long a, long long b) {
  return ((long long)abs((a / gcd(a, b)) * b));
}
long long bigmod(long long b, long long p, long long m) {
  if (!p)
    return 1 % m;
  else if (p & 1)
    return (((b % m) + m) % m * bigmod(b, p - 1, m)) % m;
  else {
    long long ret = bigmod(b, p / 2, m);
    return (ret * ret) % m;
  }
}
long long inverse(long long a, long long m) { return bigmod(a, m - 2, m); }
long long extended(long long a, long long m) {
  long long oldr = a, r = m, oldans = 1, ans = 0, quotient;
  while (r) {
    quotient = oldr / r;
    oldr = oldr - r * quotient;
    swap(oldr, r);
    oldans = oldans - ans * quotient;
    swap(oldans, ans);
  }
  return ((oldans % m) + m) % m;
}
template <class t1, class t2>
bool checkBit(t1 &mask, t2 i) {
  return mask & ((t1)1 << i);
}
template <class t1, class t2>
void setBit(t1 &mask, t2 i) {
  mask = mask | ((t1)1 << i);
}
template <class t1, class t2>
void resetBit(t1 &mask, t2 i) {
  mask = mask & ~((t1)1 << i);
}
const long long inf = (long long)1e8;
const long long mod = (long long)1e9 + 7;
int main() {
  long long yellow, blue;
  scanf("%lld %lld", &yellow, &blue);
  long long x, y, z;
  scanf("%lld %lld %lld", &x, &y, &z);
  long long Y = x * 2 + y;
  long long B = y + 3 * z;
  cout << max(0LL, Y - yellow) + max(0LL, B - blue) << endl;
  return 0;
}
