#include <bits/stdc++.h>
using namespace std;
void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int n, m;
bool check(int a) {
  int ile2 = a / 2 - a / 6;
  int ile3 = a / 3 - a / 6;
  int ile6 = a / 6;
  if (ile2 >= n) {
    if (ile3 + ile6 >= m) return true;
    return false;
  }
  int dt = n - ile2;
  ile6 -= dt;
  if (ile6 >= 0 && ile3 + ile6 >= m) return true;
  return false;
}
int main() {
  init_ios();
  cin >> n >> m;
  int x1 = 1, x2 = (int)1e9, x3;
  while (x2 - x1 > 1) {
    x3 = (x1 + x2) / 2;
    if (check(x3))
      x2 = x3;
    else
      x1 = x3;
  }
  if (check(x1))
    cout << x1 << "\n";
  else
    cout << x2 << "\n";
}
