#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, ball;
  cin >> a >> b;
  long long req = 0;
  for (int i = 1; i <= 3; i++) {
    cin >> ball;
    if (i == 1) {
      if ((ball * 2 - a) > 0) {
        req += ball * 2 - a;
        a = 0;
      } else {
        a -= 2 * ball;
      }
    }
    if (i == 2) {
      if ((ball - a) > 0) {
        req += ball - a;
        a = 0;
      } else
        a -= ball;
      if ((ball - b) > 0) {
        req += ball - b;
        b = 0;
      } else
        b -= ball;
    }
    if (i == 3) {
      if ((ball * 3 - b) > 0) {
        req += ball * 3 - b;
        b = 0;
      } else {
        b -= 3 * ball;
      }
    }
  }
  cout << req;
  return 0;
}
