#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a, b, x, y, z;
  scanf("%I64d%I64d%I64d%I64d%I64d", &a, &b, &x, &y, &z);
  int64_t addA, addB;
  if (2LL * x + y - a > 0)
    addA = 2LL * x + y - a;
  else
    int64_t addA = 0;
  if (3LL * z + y - b > 0)
    addB = 3LL * z + y - b;
  else
    addB = 0;
  printf("%I64d\n", addA + addB);
  return 0;
}
