#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int n, m;
int l[N], r[N];
int main() {
  scanf("%d%d", &n, &m);
  printf("%d\n", min(m - 1, n - m) + n * 3);
  return 0;
}
