#include <bits/stdc++.h>
using namespace std;
int main() {
  long long yelJ, bulJ, yelB, greB, bulB, sumJ, xyelJ, xbulJ, xsumJ;
  while (cin >> yelJ >> bulJ) {
    sumJ = 0;
    cin >> yelB >> greB >> bulB;
    xyelJ = (yelB * 2 + greB) - yelJ;
    xbulJ = (greB + bulB * 3) - bulJ;
    if (xyelJ < 0) xyelJ = 0;
    if (xbulJ < 0) xbulJ = 0;
    sumJ = xyelJ + xbulJ;
    cout << sumJ << endl;
  }
  return 0;
}
