#include <bits/stdc++.h>
using namespace std;
const long long int N1 = 1000010;
const long long int N2 = 2000010;
const long long int mod1 = 1e2 + 7;
const long long int mod2 = 1e9 + 7;
double pw(double x) { return (x * x); }
double dis(double x1, double y1, double x2, double y2) {
  return sqrt(pw(x1 - x2) + pw(y1 - y2));
}
double Circle_line(double a, double b, double c, double x, double y) {
  return (abs(a * x + b * y + c) / sqrt(pw(a) + pw(b)));
}
double Co_linear(double x1, double y1, double x2, double y2, double x3,
                 double y3) {
  return x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
}
bool Rotate_page(double x1, double y1, double x2, double y2, double x3,
                 double y3) {
  double d1 = dis(x1, y1, x2, y2), d2 = dis(x2, y2, x3, y3);
  if (d1 != d2) return 0;
  if (!Co_linear(x1, y1, x2, y2, x3, y3)) return 0;
  return 1;
}
double Polgn_area(double x[], double y[], long long int n) {
  double a = 0;
  int j = n;
  for (int i = 1; i <= n; i++) {
    a += (x[j] + x[i]) * (y[j] - y[i]);
    j = i;
  }
  return abs(a / 2.0);
}
double angle(double a, double b, double c) {
  return acos((pw(b) + pw(c) - pw(a)) / (2.0 * b * c));
}
const int N = 1e6 + 6;
long long int arr[N], brr[N];
int main() {
  long long int a, b;
  cin >> a >> b;
  long long int x, y, z;
  cin >> x >> y >> z;
  long long int p = 2 * x + y, q = y + 3 * z;
  long long int res = 0;
  if (p > a) res = p - a;
  if (q > b) res += (q - b);
  cout << res << "\n";
  return 0;
}
