#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, x, y, ans, i;
  cin >> n >> m;
  ans = -1;
  for (i = 5000000; i >= 2; i--) {
    x = (i / 2) - (i / 6);
    y = (i / 3) - (i / 6);
    if (max(0ll, n - x) + max(0ll, m - y) <= i / 6) {
      if (ans == -1)
        ans = i;
      else
        ans = min(ans, i);
    }
  }
  cout << ans;
  return 0;
}
