#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, m, n, x, y, z(0), a, b, c;
  string s;
  cin >> n >> m;
  cin >> a >> b >> c;
  x = 2 * a + b;
  y = 3 * c + b;
  if (x > n) z += x - n;
  if (y > m) z += y - m;
  cout << z << endl;
  return 0;
}
