#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int a[N];
bool vis[N];
int main() {
  int n, m;
  cin >> n >> m;
  int mn = min((m - 1), (n - m));
  cout << (n + 1) + n + ((n - 1) + mn);
  return 0;
}
