#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000000;
int vis[maxn];
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF) {
    int N = 2 * n;
    int M = 3 * m;
    for (int i = 1; i <= n; i++) vis[i * 2] = 1;
    for (int i = 1; i <= m; i++) vis[3 * i] = 1;
    int k = min(N / 6, M / 6);
    while (k) {
      if (N <= M) {
        N += 2;
        if (vis[N] == 0) {
          k--;
          vis[N] = 1;
        }
      } else {
        M += 3;
        if (vis[M] == 0) {
          k--;
          vis[M] = 1;
        }
      }
    }
    printf("%d\n", max(N, M));
  }
  return 0;
}
