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