#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int yc, bc;
  cin >> yc >> bc;
  long long int yb, gb, bb;
  cin >> yb >> gb >> bb;
  long long int req = 0;
  long long int y_req = yb * 2 + gb;
  long long int b_req = bb * 3 + gb;
  if (y_req - yc >= 0) req += y_req - yc;
  if (b_req - bc >= 0) req += b_req - bc;
  cout << req;
  return 0;
}
