#include <bits/stdc++.h>
using namespace std;
long long ans(long long a, long long b) {
  cout << a << " " << b << endl;
  if (a == 0)
    return 0;
  else
    return 2 * min(a, b) + ans(min(a, b), max(a, b) - min(a, b));
}
int main() {
  long long n, x;
  cin >> n >> x;
  if (n > 1010) return 0;
  cout << n + ans(n - x, x) - 1 << endl;
  return 0;
}
