#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int y = 0, b = 0, a, B, c, d, e;
  cin >> a >> B >> c >> d >> e;
  y += c * 2, y += d, b += d, b += 3 * e;
  y -= a;
  b -= B;
  if (y <= 0 && b > 0) {
    cout << b << "\n";
    return 0;
  } else if (b <= 0 && y > 0) {
    cout << y << "\n";
    return 0;
  }
  if (y + b <= 0) {
    cout << 0;
    return 0;
  }
  cout << y + b;
}
