#include <bits/stdc++.h>
using namespace std;
long long maxx(long long x, long long y) { return x > y ? x : y; }
int main() {
  long long a, b, x, y, z, aa, bb;
  cin >> a >> b >> x >> y >> z;
  aa = 2 * x + y;
  bb = 3 * z + y;
  printf("%lld\n", maxx(0, aa - a) + maxx(0, bb - b));
  return 0;
}
