#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int y, b, ansy, ansb, gy, gb, g;
  cin >> gy >> gb;
  cin >> y >> g >> b;
  ansy = (2 * y) + g;
  ansb = (3 * b) + g;
  if (ansy < gy)
    ansy = 0;
  else
    ansy = ansy - gy;
  if (ansb < gb)
    ansb = 0;
  else
    ansb = ansb - gb;
  cout << ansy + ansb;
}
