#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  if (n == 1)
    return 1;
  else
    return factorial(n - 1) * n;
}
long long digit_sum(long long n) {
  long long sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, x, y, z;
  cin >> a >> b >> x >> y >> z;
  long long ans1 = 2 * x + y - a, ans2 = y + 3 * z - b;
  if (ans1 <= 0) ans1 = 0;
  if (ans2 <= 0) ans2 = 0;
  cout << ans1 + ans2 << "\n";
  return 0;
}
