#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, z, A, B, q, k;
  cin >> A >> B;
  cin >> x >> y >> z;
  q = (x * 2) + y;
  k = (z * 3) + y;
  if (q - A >= 0 && k - B >= 0)
    cout << (q - A) + (k - B) << endl;
  else if (q - A < 0 && k - B >= 0)
    cout << (k - B) << endl;
  else if (q - A >= 0 && k - B < 0)
    cout << (q - A) << endl;
  else
    cout << 0 << endl;
  return 0;
}
