#include <bits/stdc++.h>
using namespace std;
int main() {
  long long y, b;
  cin >> y >> b;
  long long k1, k2, k3;
  cin >> k1 >> k2 >> k3;
  long long bb = 0LL, yy = 0LL;
  bb += (3LL * k3), yy += (2LL * k1);
  bb += k2, yy += k2;
  long long resp1 = max(0LL, bb - b);
  long long resp2 = max(0LL, yy - y);
  cout << resp1 + resp2 << endl;
  return 0;
}
