#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e5 + 5;
const int INF = 1e9 + 7;
long long a[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  long long l = 0, r = 1e9 + 7;
  while (r - l > 1) {
    long long mid = l + (r - l) / 2;
    if (mid / 2 + mid / 3 - mid / 6 >= n + m && mid / 2 >= n && mid / 3 >= m) {
      r = mid;
    } else
      l = mid;
  }
  cout << r;
}
