#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ullong = unsigned long long;
std::chrono::system_clock::time_point start;
void TimeStart(void) { start = std::chrono::system_clock::now(); }
void TimeEnd(void) {
  auto time = std::chrono::system_clock::now() - start;
  auto msec =
      std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
  cerr << endl << msec << " msec" << endl;
}
class AGC001B {
 public:
  AGC001B() {
    cin >> n_;
    cin >> x_;
    ans_ = 0;
  }
  void Run(void) {
    ans_ += x_;
    if (Length1(x_, n_ - x_)) {
      cout << ans_;
      return;
    }
    Length2(n_ - x_, n_ % (n_ - x_));
    cout << ans_;
  }

 private:
  bool Length1(llong n, llong x) {
    if (n % x == 0) {
      cout << "a" << endl;
      ans_ += (n / x * 2) * x;
      cout << ans_ << endl;
      return true;
    } else {
      cout << "b" << endl;
      ans_ += (n / x * 2 + 1) * x;
      cout << ans_ << endl;
    }
    return false;
  }
  void Length2(llong n, llong x) {
    llong next_n = x;
    llong next_x = n % x;
    if (next_x == 0) {
      cout << "a" << endl;
      ans_ += (n / x * 2 - 1) * x;
      cout << ans_ << endl;
      return;
    } else {
      cout << "b" << endl;
      ans_ += (n / x * 2) * x;
      cout << ans_ << endl;
    }
    Length2(next_n, next_x);
  }
  llong n_;
  llong x_;
  llong ans_;
};
int main() {
  AGC001B agc001b;
  TimeStart();
  agc001b.Run();
  TimeEnd();
  return 0;
}
