#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long t[5000010];
inline bool OK(long long mid) {
  long long a = mid / 2, b = mid / 3, c = mid / 6;
  a -= c, b -= c;
  long long x = max(n - a, 0ll), y = max(m - b, 0ll);
  return x + y <= c;
}
int main() {
  scanf("%I64d%I64d\n", &n, &m);
  long long l = 0, r = 10000000, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (OK(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%I64d\n", l);
}
