#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
bool compare(const pair<int, int>& lhs, const pair<int, int>& rhs) {
  return lhs.first < rhs.first;
}
bool compare(const int* l, const int* r) { return l < r; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long y = 0, x = 0, z = 0;
    cin >> x >> y >> z;
    long long ty = 0, tb = 0;
    ty += ((2 * x) + y);
    tb += ((3 * z) + y);
    long long ans1 = ty - a, ans2 = tb - b;
    long long f = 0;
    if (ans1 > 0) f += ans1;
    if (ans2 > 0) f += ans2;
    cout << f;
  }
  return 0;
}
