#include <bits/stdc++.h>
using namespace std;
void sprint(string s) {
  for (int i = 0; i < s.size(); ++i) printf("%c", s[i]);
  printf("\n");
}
bool f(int id, int n, int m) {
  int y = id / 6;
  int x = id / 2 - y;
  int z = id / 3 - y;
  n = max(0, n - x);
  m = max(0, m - z);
  if (n + m <= y) return 1;
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  int l = 1, r = 6000000, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (f(mid, n, m))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
