#include <bits/stdc++.h>
using namespace std;
long long n, m, t, a, b;
int main() {
  cin >> n >> m;
  long long x, y, z;
  cin >> x >> y >> z;
  a = 2 * x + y;
  t += (bool(a > n) ? a - n : 0);
  b = y + 3 * z;
  t += (bool(b > m) ? b - m : 0);
  cout << t;
}
