#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-7;
const long long MOD = 1e9 + 7;
const int MAX_N = 50;
int main() {
  long long n, m, a, b, c;
  cin >> n >> m;
  cin >> a >> b >> c;
  cout << max(0LL, a * 2 + b - n) + max(0LL, b + c * 3 - m) << endl;
  return 0;
}
