#include <bits/stdc++.h>
using namespace std;
const int PI = acos(-1.0);
const int MOD = 1e9 + 7;
void test() {}
int main() {
  ios_base::sync_with_stdio(false);
  test();
  long long A, B;
  long long X, Y, Z;
  cin >> A >> B;
  cin >> X >> Y >> Z;
  A -= 2 * X;
  B -= Y;
  A -= Y;
  B -= 3 * Z;
  long long additionalA = A < 0LL ? -A : 0LL;
  long long additionalB = B < 0LL ? -B : 0LL;
  cout << additionalA + additionalB << endl;
  return 0;
}
