#include <bits/stdc++.h>
using namespace std;
class TaskA {
 public:
  void solve(std::istream &in, std::ostream &out) {
    long long a, b, x, y, z;
    in >> a >> b >> x >> y >> z;
    long long p, q;
    p = 2 * x + y;
    q = y + 3 * z;
    out << max(0ll, (p - a)) + max(0ll, (q - b));
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  TaskA solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
