#include <bits/stdc++.h>
using namespace std;
int main() {
  long long yellow, blue;
  cin >> yellow >> blue;
  long long ny, ng, nb;
  cin >> ny >> ng >> nb;
  yellow -= ny * 2;
  yellow -= ng;
  blue -= ng;
  blue -= 3 * nb;
  long long ans = 0;
  if (yellow < 0) ans += yellow * -1;
  if (blue < 0) ans += blue * -1;
  cout << ans << endl;
}
