#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, k1 = 0, k2 = 0, jk = 0;
  cin >> a >> b;
  long long int x, y, z;
  cin >> x >> y >> z;
  k1 = x * 2 + y;
  k2 = z * 3 + y;
  if (k1 <= a && k2 <= b) {
    cout << "0";
  } else if (k1 <= a) {
    jk = jk + abs(k2 - b);
    cout << jk;
  } else if (k2 <= b) {
    jk = abs(k1 - a);
    cout << jk;
  } else {
    jk = abs(k1 - a);
    jk = jk + abs(k2 - b);
    cout << jk;
  }
}
