#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int m, n;
  long long int y, g, b;
  cin >> m >> n;
  cin >> y >> g >> b;
  long long int p, q;
  p = (y * 2) + g;
  q = (b * 3) + g;
  long long int s1 = 0;
  long long int s2 = 0;
  if (p > m) s1 = p - m;
  if (q > n) s2 = q - n;
  cout << (s1 + s2);
  return 0;
}
