#include <bits/stdc++.h>
using namespace std;
long N, X;
int main() {
  cin >> N >> X;
  vector<long> e;
  e.push_back(X);
  e.push_back(N - X);
  e.push_back(N);
  e.push_back(N - X);
  long edge_sum = X;
  while (1) {
    long s = 0;
    int index = 5;
    for (int i = 0; i < 4; i++) {
      if (s < e[i]) {
        s = e[i];
        index = i;
      }
    }
    if (index == 3) {
      e[index] -= e[index - 1];
      edge_sum += e[index - 1];
    } else {
      e[index] -= e[index + 1];
      edge_sum += e[index + 1];
    }
    if (e[0] * e[1] * e[2] * e[3] == 0) {
      break;
    }
  }
  cout << edge_sum << endl;
  return 0;
}
