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