#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int A, B;
  cin >> A >> B;
  long long int x, y, z;
  long long int ye = 0, be = 0;
  cin >> x >> y >> z;
  if (A >= 2 * x + y)
    ye = 0;
  else
    ye = (2 * x + y - A);
  if (B >= y + 3 * z)
    be = 0;
  else
    be = (y + 3 * z - B);
  cout << (ye + be) << "\n";
  return 0;
}
