#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, x, y, z, yellow, blue, zero = 0;
  cin >> a >> b >> x >> y >> z;
  yellow = 2 * x + y, blue = y + 3 * z;
  cout << max(zero, yellow - a) + max(zero, blue - b) << endl;
  return 0;
}
