#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 - A;
  b = y + 3 * z - B;
  if (a < 0) a = 0;
  if (b < 0) b = 0;
  cout << a + b << endl;
  return 0;
}
