#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, z, ans1, ans2;
char tp[100000], *p1 = tp, *p2 = tp;
inline char get_char() {
  return p1 == p2 && (p2 = (p1 = tp) + fread(tp, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int date = 0, w = 1;
  char c = 0;
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = get_char();
  }
  while (c >= '0' && c <= '9') {
    date = date * 10 + c - '0';
    c = get_char();
  }
  return date * w;
}
void solve() {
  a = read();
  b = read();
  x = read();
  y = read();
  z = read();
  ans1 = (x * 2 + y - a);
  ans2 = (y + z * 3 - b);
  if (ans1 < 0) ans1 = 0;
  if (ans2 < 0) ans2 = 0;
  printf("%lld\n", ans1 + ans2);
}
int main() {
  solve();
  return 0;
}
