#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y, z, k = 0;
  cin >> a >> b;
  cin >> x >> y >> z;
  a -= y;
  a -= x * 2;
  b -= y;
  b -= z * 3;
  if (a < 0) k -= a;
  if (b < 0) k -= b;
  if (k > 0)
    cout << k;
  else
    cout << 0;
}
