#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int main() {
  long long a, b;
  long long x, y, z;
  while (scanf("%lld %lld", &a, &b) == 2) {
    scanf("%lld %lld %lld", &x, &y, &z);
    long long A = x * 2ll + y;
    long long B = y + z * 3ll;
    A = max(0ll, A - a);
    B = max(0ll, B - b);
    printf("%lld\n", A + B);
  }
  return 0;
}
