#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a > b) return b;
  return a;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
int main() {
  long long n, m, a, b, c;
  cin >> n >> m;
  cin >> a >> b >> c;
  n = n - a * 2 - b;
  m = m - b - c * 3;
  n = min(0, n);
  m = min(0, m);
  cout << -1 * (m + n);
}
