#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long a, b, x, z, y;
  cin >> a >> b >> x >> y >> z;
  unsigned long long s1 = (x * 2) + y;
  unsigned long long s2 = (3 * z) + y;
  s1 = max(a, s1) - a;
  s1 += max(b, s2) - b;
  cout << s1;
}
