#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int cy, cb;
  cin >> cy >> cb;
  long long int ty, tg, tb;
  cin >> ty >> tg >> tb;
  long long int added = 0;
  if (cy >= tg && cb >= tg) {
    cy -= tg;
    cb -= tg;
    if ((2 * ty - cy) > 0) added += (2 * ty - cy);
    if ((3 * tb - cb) > 0) added += (3 * tb - cb);
  } else if (cy <= tg && cb <= tg) {
    long long int miss1 = tg - cy;
    long long int miss2 = tg - cb;
    added += (miss1 + miss2);
    added += (2 * ty + 3 * tb);
  } else if (cy <= cb && cy <= tg) {
    long long int miss1 = tg - cy;
    added += miss1;
    cb -= tg;
    if ((3 * tb - cb) > 0) added += (3 * tb - cb);
    added += 2 * ty;
  } else if (cb <= cy && cb <= tg) {
    long long int miss2 = tg - cb;
    added += miss2;
    cy -= tg;
    if ((2 * ty - cy) > 0) added += (2 * ty - cy);
    added += 3 * tb;
  }
  cout << added << '\n';
}
