#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 rnd(239);

int main() {
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  vector <ll> fibo(100);
  fibo[0] = 1;
  fibo[1] = 1;
  vector <ll> q;
  q.push_back(1);
  for (int i = 2; i < 100; i++) {
    fibo[i] = fibo[i - 1] + fibo[i - 2];
    if (fibo[i] <= m) {
      q.push_back(fibo[i]);
    } else {
      break;
    }
  }
  reverse(q.begin(), q.end());
  vector <ll> arr(60, -1);
  vector <vector <ll> > cur;
  for (int i = 0; i < (int) q.size(); i++) {
    ll x = q[i];
    for (int j = 0; j < 60; j++) {
      if ((x >> j) & 1) {
        if (arr[j] == -1) {
          arr[j] = x;
          break;
        } else {
          x ^= arr[j];
        }
      }
    }
    cur.push_back(arr);
  }
  int inf = 1e9;
  int ans = inf;
  function<void(int, ll, ll, int)> dfs = [&] (int i, ll xr, ll s, int cnt) {
    if (s > m) return;
    if (i == -1) {
      if (xr != n) return;
      ll rem = m - s;
      if (rem % 2) return;
      rem /= 2;
      for (ll t : q) {
        while (rem >= t) {
          rem -= t;
          cnt += 2;
        }
      }
      ans = min(ans, cnt);
      return;
    } else {
      ll need = xr ^ n;
      for (int j = 0; j < 60; j++) {
        if ((need >> j) & 1) {
          if (cur[i][j] == -1) return;
          need ^= cur[i][j];
        }
      }
      dfs(i - 1, xr, s, cnt);
      dfs(i - 1, xr ^ q[i], s + q[i], cnt + 1);
    }
  };
  dfs((int) q.size() - 1, 0, 0, 0);
  if (ans == inf) ans = -1;
  cout << ans << '\n';
}
