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