#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int INF = 1e9;
int main() {
  long long int n, x;
  cin >> n >> x;
  if (n % x == 2) {
    cout << (3 * n) / 2 << endl;
  } else if (2 * x < n) {
    cout << 6 * x << endl;
  } else {
    cout << 3 * x << endl;
  }
  return 0;
}
