#include <bits/stdc++.h>
using namespace std;
int main() {
  long long yellowB, greenB, blueB, yellow, blue;
  long long temp;
  cin >> yellow >> blue >> yellowB >> greenB >> blueB;
  long long resY = (yellowB * 2 + greenB - yellow);
  long long resB = (blueB * 3 + greenB - blue);
  long long res = 0;
  if (resY > 0) res += resY;
  if (resB > 0) res += resB;
  cout << res << endl;
  return 0;
}
