#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const int M = 345678;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, c, x, y;
  cin >> x >> y;
  cin >> a >> b >> c;
  long long yl = a * 2 + b, bl = 3 * c + b;
  long long ans = max(0LL, yl - x) + max(0LL, bl - y);
  cout << ans << endl;
  return 0;
}
