#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  long long n, m;
  cin >> n >> m;
  if (2LL * m == n)
    cout << n + m << endl;
  else
    cout << 3LL * (n - 1) << endl;
  return 0;
}
