#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  long long common;
  if (M * 3 >= N * 2)
    common = N * 2 / 3 / 2;
  else
    common = (M * 3) / 2 / 3;
  while (common) {
    if (N * 2 <= M * 3) {
      N++;
      if ((N * 2) % 3 || (N * 2) % 3 == 0 && N * 2 > M * 3) common--;
    } else {
      M++;
      if ((M * 3) % 2 || (M * 3) % 2 == 0 && M * 3 > N * 2) common--;
    }
  }
  cout << max(N * 2, M * 3);
  return 0;
}
