#include <bits/stdc++.h>
int set1[10000001] = {0};
int set2[10000001] = {0};
int main() {
  int left, right, i, count = 1, check = 0;
  scanf("%d%d", &left, &right);
  for (i = 2; i <= 1e7; i += 2) set1[count++] = i;
  count = 1;
  for (i = 3; i <= 1e7; i += 3) set2[count++] = i;
  int temp, left_use = 0, right_use = 0;
  if ((set1[left] / 6) >= (set2[right] / 6))
    temp = set2[right] / 6;
  else if ((set1[left] / 6) < (set2[right] / 6))
    temp = set1[left] / 6;
  for (i = 0; i < temp; i++) {
    if (set1[left + 1] > set2[right + 1]) {
      right += 1;
      right_use = 1;
    } else if (set1[left + 1] <= set2[right + 1]) {
      left += 1;
      left_use = 1;
    }
    if ((left_use == 1) && (set1[left] % 6 == 0)) {
      if (set2[right] > set1[left]) temp++;
      left_use = 0;
    } else if ((right_use == 1) && (set2[right] % 6 == 0)) {
      if (set1[left] > set2[right]) temp++;
      right_use = 0;
    }
    if (set1[left] == set2[right]) temp++;
  }
  if (set1[left] > set2[right])
    printf("%d", set1[left]);
  else if (set1[left] < set2[right])
    printf("%d", set2[right]);
  return 0;
}
