#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int y, b;
  cin >> y >> b;
  long long int ny, ng, nb;
  cin >> ny >> ng >> nb;
  long long int sy, sb;
  sy = 2 * ny + ng;
  sb = 3 * nb + ng;
  long long int s;
  if (sy > y) s = sy - y;
  if (sb > b) s = s + sb - b;
  cout << s;
}
