#include <bits/stdc++.h>
using namespace std;
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b % 2) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long int mmi(long long int a) { return power(a, mod - 2); }
long long int cntbit(long long int n) {
  long long int cnt = 0;
  while (n) {
    n &= (n - 1);
    cnt++;
  }
  return cnt;
}
long long int a, b, yl, gr, bl;
void solve() {
  cin >> a >> b;
  cin >> yl >> gr >> bl;
  long long int x = 2 * yl + gr;
  long long int y = 3 * bl + gr;
  x = max(0LL, x - a);
  y = max(0LL, y - b);
  cout << x + y;
}
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
