using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program
{
    public static class CODEFORCES1
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var p = NN;
            var ans = 10000;
            for (var i = 0; i <= 33; i++)
            {
                var tmp = n - p * i;
                var mask = 1;
                var tmp2 = 0;
                for (var j = 0; j <= 33; j++)
                {
                    if ((mask & tmp) != 0) ++tmp2;
                    mask <<= 1;
                }
                if (tmp2 <= i && tmp >= i)
                {
                    ans = Min(ans, i);
                }
            }
            if (ans == 10000)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(ans);
            }

        }
        static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; }
        static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; }
        static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } }
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; }
        static long LCM(long a, long b) => a * b / GCD(a, b);
        static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; }
        static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; }
        static List<long> _fact = new List<long>() { 1 };
        static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
        static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
        static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); }
        static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); }
        static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); }
        static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); }
        static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); }
        static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } }
        static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; }
        class PQ<T>
        {
            List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count;
            public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); }
            public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); }
            public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
            public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
            public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; }
            public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; }
        }
        class PQ<TK, TV>
        {
            PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count;
            public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); }
            public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); }
            public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
            public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
            public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
            public Tuple<TK, TV> Pop() => q.Pop();
        }
        public class UF
        {
            long[] d;
            public UF(long s) { d = Repeat(-1L, s).ToArray(); }
            public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; }
            public bool IsSame(long x, long y) => Root(x) == Root(y);
            public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
            public long Count(long x) => -d[Root(x)];
        }
        struct Mod : IEquatable<Mod>, IEquatable<long>
        {
            static public long _mod = 1000000007; long v;
            public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; }
            static public implicit operator Mod(long x) => new Mod(x);
            static public implicit operator long(Mod x) => x.v;
            public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; }
            public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; }
            public void Mul(Mod x) => v = (v * x.v) % _mod;
            public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
            static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; }
            static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; }
            static public Mod operator *(Mod x, Mod y) => x.v * y.v;
            static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
            static public bool operator ==(Mod x, Mod y) => x.v == y.v;
            static public bool operator !=(Mod x, Mod y) => x.v != y.v;
            static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; }
            public bool Equals(Mod x) => v == x.v;
            public bool Equals(long x) => v == x;
            public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
            public override int GetHashCode() => v.GetHashCode();
            public override string ToString() => v.ToString();
            static List<Mod> _fact = new List<Mod>() { 1 };
            static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
            static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
            static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        }
        class Tree
        {
            long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs;
            public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; }
            public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; }
            public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
            public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; }
            public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; }
        }
        class BT<T> where T : IComparable
        {
            class Node { public Node l; public Node r; public T v; public bool b; public int c; }
            Comparison<T> c; Node r; bool ch; T lm;
            public BT(Comparison<T> _c) { c = _c; }
            public BT() : this((x, y) => x.CompareTo(y)) { }
            bool R(Node n) => n != null && !n.b;
            bool B(Node n) => n != null && n.b;
            long C(Node n) => n?.c ?? 0;
            Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; }
            Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; }
            Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); }
            Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); }
            public void Add(T x) { r = A(r, x); r.b = true; }
            Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); }
            Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; }
            public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; }
            Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); }
            Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; }
            Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; }
            Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; }
            public T this[long i] { get { return At(r, i); } }
            T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); }
            public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; }
            public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x);
            long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); }
            public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; }
            long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); }
            public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; }
            public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; }
            public bool Any() => r != null;
            public long Count() => C(r);
            public IEnumerable<T> List() => L(r);
            IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; }
        }
        class Dict<K, V> : Dictionary<K, V>
        {
            Func<K, V> d;
            public Dict(Func<K, V> _d) { d = _d; }
            public Dict() : this(_ => default(V)) { }
            new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } }
        }
        class Deque<T>
        {
            T[] b; int o, c;
            public int Count;
            public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } }
            public Deque(int cap = 16) { b = new T[c = cap]; }
            int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; }
            public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; }
            public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; }
            public T Front => b[o];
            public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; }
            public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; }
            public T Back => b[gi(Count - 1)];
            void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; }
            public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; }
            public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; }
        }
        class SegTree<T>
        {
            int n; T ti; Func<T, T, T> f; T[] dat;
            public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); }
            public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } }
        }
        class LazySegTree<T, E>
        {
            int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz;
            public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
            void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; }
            void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); }
            void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); }
            public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); }
            public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); }
            public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } }
        }
        class SlidingWindowAggregation<T>
        {
            T[][] l; T[][] a; int[] n; Func<T, T, T> f;
            public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } }
            public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) { }
            public int Count => n[0] + n[1];
            void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; }
            public void PushBack(T val) => Push(1, val);
            public void PushFront(T val) => Push(0, val);
            public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; }
            public T PopBack() => Pop(1);
            public T PopFront() => Pop(0);
            public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); }
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		for(int i=1;;i++){
			if(N - i * P <= 0){
				Console.WriteLine(-1);
				return;
			}

			int cnt = 0;
			long v = N - i * P;
			if(v < i){
				Console.WriteLine(-1);
				return;
			}
			for(int j=0;j<60;j++){
				if(((v >> j) & 1) == 1) cnt++;
			}
			if(cnt <= i){
				Console.WriteLine(i);
				return;
			}

		}

	}
	long N,P;
	public Sol(){
		var d = ria();
		N = d[0]; P = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

public class SyllableSorting
{

    public static  int gcd(int a, int b)
    {
        if (b == 0) return a;
        else return a >= b ? gcd(b,a%b):gcd(b,a);
    }
    public static void Main()
    {
        //Console.SetIn(new StreamReader("C:\\Users\\saib\\Desktop\\abc.txt"));

        string str = Console.ReadLine();
        string[] values = str.Split(' ');
        int a = int.Parse(values[0]);
        int b = int.Parse(values[1]);
        int c = int.Parse(values[2]);
        int d = int.Parse(values[3]);
        if (b * c == a * d)
        {
            Console.WriteLine("0/1");
        }
        else if (b * c > a * d)
        {
            int num = b * c - a * d;
            int den = b * c;
            int temp = gcd(num,den);
            num = num / temp;
            den = den / temp;
            Console.WriteLine(num+"/"+den);
        }
        else
        {
            int num = a * d - b*c;
            int den = a*d;
            int temp = gcd(num, den);
            num = num / temp;
            den = den / temp;
            Console.WriteLine(num + "/" + den);
        }

        //Console.SetIn(new StreamReader(Console.OpenStandardInput()));
        Console.ReadLine();
     }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Routine_Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int a, b, c, d;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);
            d = int.Parse(str[3]);
            a = int.Parse(str[0]);
            if (a == b &&  c==d )
            {
                Console.WriteLine(0 + "/" + 1);return;
            }
                int ad = a * d;
                int bc = b * c;
                int up = Math.Abs(ad - bc);
                int dow = Math.Max(ad,bc);
                int G = GCD(up, dow);
                if (G==-1)
                {
                    Console.WriteLine(up.ToString() + "/" + dow.ToString());
                }
            else
                    Console.WriteLine((up/G).ToString() + "/" + dow/G);

        }
       public static int GCD(int a, int b)
        {
            double u = Math.Min(a, b);
            double d = Math.Max(a,b);
            int it = (int)u;
            while (true)
            {
                if ((u / it) == Math.Ceiling(u / it * 1.0) && (d / it) == Math.Ceiling(d / it * 1.0))
                {
                    return it;
                }
                it--;
            }
            return -1;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _626A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            string commands = Console.ReadLine();

            int result = ContigouseCiclesSubstrings(commands);

            Console.WriteLine(result);

            Console.ReadLine();
        }

        public static int ContigouseCiclesSubstrings(string commands)
        {
            int result = 0;
            Dictionary<int, int> dic = new Dictionary<int, int>(commands.Length + 1);
            dic.Add(0, 1);

            int x = 0;
            int y = 0;
            int key;

            foreach (var command in commands)
            {
                switch (command)
                {
                    case 'U': y++;
                        break;
                    case 'R': x++;
                        break;
                    case 'D': y--;
                        break;
                    case 'L': x--;
                        break;
                    default: throw new ArgumentException("Grong command");
                }
                key = GetUniqueKey(x, y);

                if (dic.ContainsKey(key))
                {
                    result += dic[key];
                    dic[key]++;
                }
                else
                    dic.Add(key, 1);
            }

            return result;
        }

        private static int GetUniqueKey(int x, int y)
        {
            //the hash function is putting the x;y as a single number in 201 base
            return x * 201 + y;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class EVC1
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));

            string strT = Console.ReadLine();
            int n = int.Parse(strT);

            strT = Console.ReadLine();
            //string[] strParams = strT.Split(new char[] { ' ' });

            ulong r = 0;
            int[] a = new int[]{0,0,0,0};
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    a[0] = 0;
                    a[1] = 0;
                    a[2] = 0;
                    a[3] = 0;
                    for (int k = i; k <= j; k++)
                    {
                        if (strT[k] == 'U')
                            a[0]++;
                        else if (strT[k] == 'R')
                            a[1]++;
                        else if (strT[k] == 'L')
                            a[2]++;
                        else //if (strT[k] == 'D')
                            a[3]++;
                    }

                    if (a[0] == a[3] && a[1] == a[2])
                        r++;
                }
            }

            Console.WriteLine(r.ToString());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var min = new int[3];
        var max = new int[3];
        for (int i = 0; i < 3; i++)
        {
            var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            min[i] = b[0];
            max[i] = b[1];
        }
        int d1 = min[0], d2 = min[1], d3 = min[2];
        n -= d1 + d2 + d3;
        while (n > 0)
        {
            if (d1 < max[0])
            {
                d1++;
                n--;
            }
            else if (d2<max[1])
            {
                d2++;
                n--;
            }
            else if (d3<max[2])
            {
                d3++;
                n--;
            }
        }
        Console.WriteLine("{0} {1} {2}", d1, d2, d3);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int min1,max1,min2,max2,min3,max3;
            string[] s = Console.ReadLine().Split(' ');
            min1=int.Parse(s[0]);
            max1=int.Parse(s[1]);
            s = Console.ReadLine().Split(' ');
            min2=int.Parse(s[0]);
            max2=int.Parse(s[1]);
            s = Console.ReadLine().Split(' ');
            min3=int.Parse(s[0]);
            max3=int.Parse(s[1]);
            int k1, k2, k3;
            //-----------
            if (n - min1 - min2 - min3 >= max1 - min1)
                k1 = max1;
            else
                k1 = min1 + n - min1 - min2 - min3;
            n = n - k1;
            //-----------
            if (n - min2 - min3 >= max2 - min2)
                k2 = max2;
            else
                k2 = min2 + n- min2 - min3;
            //-----------
            n = n - k2;
            if (n - min3 >= max3 - min3)
                k3 = max3;
            else
                k3 = n;

            Console.WriteLine(k1.ToString() + ' ' + k2.ToString() + ' ' + k3.ToString());
           // Console.ReadKey();
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace R._176.Div2.A
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] array = new char[4, 4];
            for (int i = 0; i < 4; i++)
            {
                string inputLine = Console.ReadLine();
                for (int j = 0; j < 4; j++)
                {
                    array[i, j] = inputLine[j];
                }
            }

            Dictionary<char, int> dic = new Dictionary<char, int>();
            dic['#'] = 0;
            dic['.'] = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    dic[array[i,j]] ++ ;
                    dic[array[i, j + 1]]++;
                    dic[array[i + 1, j ]]++;
                    dic[array[i + 1, j +1]]++;
                    if (dic['#'] >= 3 || dic['.'] >= 3)
                    {
                        Console.WriteLine("YES");
                        return;
                    }
                dic['#'] = 0;
                dic['.'] = 0;
                }
            }
            Console.WriteLine("NO");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            bool[,] array = new bool[4, 4];
            for (int i = 0; i < 4; i++ )
            {
                string s = Console.ReadLine();
                for (int j = 0; j < 4; j++ )
                {
                    if (s[j] == '.')
                    {
                        array[i, j] = false;
                    }
                    else
                    {
                        array[i, j] = true;
                    }
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (i + 1 < 4 && j + 1 < 4 && array[i + 1, j] && array[i + 1, j + 1] && array[i, j + 1])
                    {
                        Console.WriteLine("YES");
                        return;
                    }

                    if (i + 1 < 4 && j - 1 >= 0 && array[i + 1, j] && array[i + 1, j - 1] && array[i, j - 1])
                    {
                        Console.WriteLine("YES");
                        return;
                    }

                    if (i + 1 < 4 && j + 1 < 4 && !array[i + 1, j] && !array[i + 1, j + 1] && !array[i, j + 1])
                    {
                        Console.WriteLine("YES");
                        return;
                    }

                    if (i + 1 < 4 && j - 1 >= 0 && !array[i + 1, j] && !array[i + 1, j - 1] && !array[i, j - 1])
                    {
                        Console.WriteLine("YES");
                        return;
                    }
                }
            }

            Console.WriteLine("NO");
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Vasyas_Function
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static IEnumerable<long> Gi()
        {
            yield return 2;
            for (int i = 3;; i += 2)
            {
                yield return i;
            }
        }

        private static void Main(string[] args)
        {
            long x = Next();
            long y = Next();

            var list = new List<long>();
            foreach (long i in Gi())
            {
                if (i*i > x)
                    break;

                while (x%i == 0)
                {
                    list.Add(i);
                    x /= i;
                }
            }
            if (x != 1)
                list.Add(x);

            long count = list.Count == 0 ? y : 0;

            long yy = y;
            long d = 1;
            while (yy > 0 && list.Count > 0)
            {
                long min = list.Select(l => y%l).Concat(new[] {y}).Min();

                count += min;
                y -= min;
                yy -= d*min;

                for (int i = 0; i < list.Count; i++)
                {
                    if (y%list[i] == 0)
                    {
                        y /= list[i];
                        d *= list[i];
                        list.RemoveAt(i);
                        i--;
                    }
                }

                if (list.Count == 0)
                {
                    count += yy/d;
                }
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static long Next()
        {
            int c;
            long res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        long X, Y;
        sc.Make(out X, out Y);
        var div = new List<long>();
        for(long i=1;i*i<=X;i++)
            if (X % i == 0)
            {
                if (i != 1)
                    div.Add(i);
                if (i * i != X) div.Add(X / i);
            }
        var now = GCD(X, Y);
        Y /= now;
        X /= now;
        var res = 0L;
        while (Y != 0)
        {
            var max = 0L;
            foreach (var d in div)
            {
                var y = Y / d * d;
                if (GCD(y, X) == 1) continue;
                chmax(ref max, y);
            }
            res += Y - max;
            Y = max;
            var v = GCD(Y, X);
            now *= v;
            X /= v;
            Y /= v;
        }
        Console.WriteLine(res);
    }
     #region GCD
    public static int LCM(int num1, int num2)
        => num1 / GCD(num1, num2) * num2;

    public static long LCM(long num1, long num2)
        => num1 / GCD(num1, num2) * num2;

    public static int GCD(int num1, int num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;

    public static long GCD(long num1, long num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;
    #endregion
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var num = Input.num;
        var str = new[] { "A", "A", "B", "A" };
        var a = new[] { 1, 0, 1, 2 };
        WriteLine($"{a[num%4]} {str[num % 4]}");
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static T[] create<T>(int n, Func<int, T> f)
        => Enumerable.Repeat(0, n).Select(f).ToArray();
    public static char[][] gred(int h)
        => create(h, _ => read.ToCharArray());
    public static int[] ar1D(int n)
        => create(n, _ => num);
    public static long[] arL1D(int n)
        => create(n, _ => numL);
    public static string[] strs(int n)
        => create(n, _ => read);
    public static int[][] ar2D(int n)
        => create(n, _ => ar);
    public static long[][] arL2D(int n)
        => create(n, _ => arL);
    public static List<T>[] edge<T>(int n)
        => create(n, _ => new List<T>());
    public static T GetValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static void Make<T1, T2>(out T1 v1, out T2 v2)
    {
        v1 = Next<T1>();
        v2 = Next<T2>();
    }
    public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        Make(out v1, out v2);
        v3 = Next<T3>();
    }
    public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4)
    {
        Make(out v1, out v2, out v3);
        v4 = Next<T4>();
    }
    public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5)
    {
        Make(out v1, out v2, out v3, out v4);
        v5 = Next<T5>();
    }
    public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6)
    {
        Make(out v1, out v2, out v3, out v4, out v5);
        v6 = Next<T6>();
    }
    private static Queue<string> sc = new Queue<string>();
    public static T Next<T>(){ if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}


using System;

namespace Task_01
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine()) % 4;
            switch (n)
            {
                case 0: Console.WriteLine("1 A"); break;
                case 1: Console.WriteLine("0 A"); break;
                case 2: Console.WriteLine("1 B"); break;
                case 3: Console.WriteLine("2 A"); break;
            }
        }
    }
}


using System;

namespace ConsoleApplication
{
	class Program
	{
		static void Main(string[] args)
		{
			string str = Console.ReadLine();

			if (str != null)
			{
				string[] arr = str.Split(' ');

				int n = int.Parse(arr[0]);
				int a = int.Parse(arr[1]);

				int result;
				if (a % 2 == 0)
				{
					result = n / 2 - a / 2 + 1;
				}
				else
				{
					result = a / 2 + a % 2;
				}

				Console.Write(result);
			}
		}

	}
}


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

namespace ConsApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            String[] sm = s.Split(' ');
            int n = int.Parse(sm[0]);
            int a = int.Parse(sm[1]);
            int res = 1;

            if (a % 2 == 0)
            {
                res += (n / 2) - (a / 2);

            }
            else
            {
                res += (a-1) / 2 ;

            }

            Console.WriteLine(res);

        }
    }
}


using System;
using System.IO;
using System.Text;

namespace A_Prank
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int n = Next();

            var nn = new int[n + 2];
            for (int i = 1; i <= n; i++)
            {
                nn[i] = Next();
            }
            nn[0] = 0;
            nn[n + 1] = 1001;

            int ans = 0;
            int cnt = 1;

            for (int i = 1; i < nn.Length; i++)
            {
                if (nn[i] == nn[i - 1] + 1)
                {
                    cnt++;
                }
                else
                {
                    if (cnt >= 3)
                        ans = Math.Max(ans, cnt - 2);
                    cnt = 1;
                }
            }
            if (cnt >= 3)
                ans = Math.Max(ans, cnt - 2);
            return ans;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var e = Convert.ToInt32(Console.ReadLine());
            var a = Console.ReadLine();
            var numbers = Array.ConvertAll(a.Split(' '), n => Int32.Parse(n));
            var substrings = new List<int>();
            for (int i = 0, step = 1, count = 0; e != 1 && i < e;)
            {
                if (i + step < e && numbers[i + step] == numbers[i] + step) step++;
                else
                {
                    if (step >= 2)
                    {
                        if (numbers[i] == 1 || numbers[i + step - 1] == 1000) count += step - 1;
                        else
                        {
                            count += step - 2;
                        }
                        substrings.Add(count);
                        count = 0;
                        step = 1;
                    }
                    i += step;
                }
            }

            if (substrings.Count == 0) Console.Write(0);
            else Console.WriteLine(substrings.Max());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace code
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int l = arr[0];
            int d = arr[1];
            double v = arr[2];
            int g = arr[3];
            int r = arr[4];
            double t = (double)d / v;
            double time;
            string str = "";
            while (true)
            {
                if (t - g < 0)
                {
                    str = String.Format("{0:f6}",l/v);
                    str = str.Replace(',', '.');
                    Console.WriteLine(str);
                    return;
                }
                t = t - g;
                if (t - r < 0)
                {
                    time = r - t;
                    time += (double)d / v+(l-d)/v;
                    str = String.Format("{0:f6}", time);
                    str=str.Replace(',', '.');
                    Console.WriteLine(str);
                    return;
                }
                t -= r;

            }
        }
    }
}


namespace _29B
{
    using System;

    public class Program
    {
        public static void Main(string[] args)
        {
            double[] paramsTask = Array.ConvertAll(Console.ReadLine().Split(' '), c => double.Parse(c));
            double roadLength = paramsTask[0], trafficLightLength = paramsTask[1], carSpeed = paramsTask[2], greenSpeed = paramsTask[3], redSpeed = paramsTask[4], result = 0, summ = 0, counter = 0;

            result = trafficLightLength / carSpeed;

            while (true)
            {
                if (summ > result)
                {
                    if (counter % 2 == 0)
                    {
                        result = summ;
                    }

                    break;
                }

                if (counter % 2 == 0)
                {
                    summ += greenSpeed;
                }
                else
                {
                    summ += redSpeed;
                }

                counter++;
            }

            result += (roadLength - trafficLightLength) / carSpeed;

            Console.WriteLine(Math.Round(result, 8).ToString().Replace(",", "."));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp59
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()),x = 0,res = 0;
            string s = Console.ReadLine();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s.Split(' ')[i]);
                if (x == 0 && a[i] != 0)
                    x = i;
            }
            for(int i = x; i < n; i++)
            {
                if(x != 0)
                    res += a[i]*(4*i);
            }
            Console.WriteLine(res);
        }
    }
}


// Problem: 1084A - The Fair Nut and Elevator
// Author: Gusztav Szmolik

using System;

class TheFairNutAndElevator
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        byte n;
        if (!Byte.TryParse (words[0], out n))
            return -1;
        if (n < 1 || n > 100)
            return -1;
        words = ReadSplitLine (n);
        if (words == null)
            return -1;
        byte[] a = new byte[n];
        ushort sumA = 0;
        uint term1 = 0;
        for (byte i = 0; i < n; i++)
            {
            byte ai;
            if (!Byte.TryParse (words[i], out ai))
                return -1;
            if (ai > 100)
                return -1;
            a[i] = ai;
            sumA += ai;
            term1 += Convert.ToUInt32 (i*ai);
            }
        uint ans = 6000000;
        ushort sumSub = sumA;
        uint term2 = 0;
        for (byte i = 0; i < n; i++)
            {
            uint numEU = 4*(term1+term2);
            if (numEU < ans)
                ans = numEU;
            sumSub -= a[i];
            term1 -= sumSub;
            term2 += sumA;
            }
        Console.WriteLine (ans);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round59
{
    class E
    {
        int[][] dx = new int[][]{
            new int[]{2,4,6},
            new int[]{1,3,5,7},
            new int[]{0,2,4,6,8},
            new int[]{1,3,5,7},
            new int[]{2,4,6}
        };

        char[][] cs = new char[5][];
        int[,] id = new int[10, 10];
        List<int> chk = new List<int>();

        bool ok(int x, int y)
        {
            return 0 <= y && y < 5 && dx[y].Contains(x);
        }

        void proc(int x, int y, int dx, int dy)
        {
            int hash = 0;
            for (; ok(x, y); x += dx, y += dy)
            {
                hash |= 1 << id[x, y];
                chk.Add(hash);
            }
        }

        E()
        {
            for (int i = 0; i < 5; i++)
                cs[i] = Console.ReadLine().ToCharArray();

            int state = 0;
            for(int y = 0, idx = 0; y < 5; y++)
                for (int i = 0; i < dx[y].Length; i++)
                {
                    int x = dx[y][i];
                    id[x,y] = idx++;
                    if (cs[y][x] == 'O')
                        state |= 1 << id[x, y];
                }

            for (int y = 0; y < 5; y++)
                for (int i = 0; i < dx[y].Length; i++)
                {
                    int x = dx[y][i];
                    proc(x, y, 2, 0);
                    proc(x, y, 1, 1);
                    proc(x, y, -1, 1);
                }

            bool[] win = new bool[1<<19];
            for (int i = 1; i < 1 << 19; i++)
            {
                foreach (int hash in chk)
                {
                    if ((i & hash) == hash && !win[i ^ hash])
                    {
                        win[i] = true;
                        break;
                    }
                }
            }

            Console.WriteLine(win[state] ? "Karlsson" : "Lillebror");
        }

        public static void Main()
        {
            new E();
        }
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;

#if DEBUG
using System.Diagnostics;
#endif

namespace _489с
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);

#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
#if DEBUG
                Solution(testNumber);
#else
                Solution(0);
#endif
            }
            finally
            {
#if DEBUG
#else
                if (_useFileInput)
                {
                    file.Close();
                }
#endif
            }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }

        static long mod = 1000 * 1000 * 1000 + 7;

        static void Solution(int testNumber)
        {
            checked
            {
                #region SOLUTION
                var d = ReadLongArray();
                var x = d[0];
                var k = d[1];

                if (x == 0)
                {
                    Console.WriteLine(0);
                    return;
                }

                x %= mod;
                k++;
                var kp = Pow(2, k);
                kp *= x;
                kp %= mod;

                var next = 1L;
                if (k == 2)
                {
                    next = -1;
                }
                else if (k == 1)
                {
                    next = 0;
                }
                else if (k > 2)
                {
                    //var gp = (1 - Pow(2, k - 2)) / (1 - 2);
                    next = -Pow(2, k - 1) + 1;
                    next %= mod;
                }

                var res = kp + next;
                if (res < 0)
                {
                    res += mod;
                }
                res %= mod;

                Console.WriteLine(res);
            }
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static long Pow(long a, long pp)
        {
            checked
            {
                var res = 1L;
                while (true)
                {
                    if (pp % 2 == 1)
                    {
                        res *= a;
                        res %= mod;
                        pp--;
                    }
                    else
                    {
                        pp /= 2;
                        a *= a;

                        a %= mod;
                    }

                    if (pp == 0)
                    {
                        break;
                    }
                }

                return res;
            }

        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.StartsWith(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bla
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long x = long.Parse(s[0]);
            long k = long.Parse(s[1]) + 1;
            if (x == 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine((((((x % mod) * pow(k)) % mod) - pow(k - 1) + 1) % mod + mod) % mod);
            }
        }

        static long mod = 1000000007;

        static long pow(long n) //2^n
        {
            if (n == 0)
                return 1;
            if(n % 2 == 0)
            {
                long a = pow(n / 2);
                return (a * a) % mod;
            }
            return (2 * pow(n - 1)) % mod;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;

class Program
{
    long maxK = 1000;
    long maxPrime = 2 * 1000000 + 10;
    int[] minDiv;
    List<long> primes = new List<long>();
    void solve()
    {
        getDiv();
        long a = nextLong();
        long b = nextLong();
        long k = nextLong();
        long res = get(b, k);
        res -= get(a - 1, k);
        println(res);

    }

    private void getDiv()
    {
        minDiv = new int[maxPrime];
        for (int i = 2; i < minDiv.Length; i++)
            minDiv[i] = i;
        for (int i = 2; i < minDiv.Length; i++)
            if (minDiv[i] == i)
                for (int j = 2 * i; j < minDiv.Length; j += i)
                    if (minDiv[j] == j)
                        minDiv[j] = i;
    }

    private long get(long n, long k)
    {
        if (n <= 0)
            return 0;
        if (!prime(k))
            return 0;
        long res=0;
        if (k >= maxK)
        {

            if (k <= n)
                res++;
            for (long x = k; x * k <= n; x++)
                if (minDiv[x] >= k)
                    res++;
            return res;
        }
        else
        {
            for(int i=2;i<k;i++)
                if (minDiv[i] == i)
                {
                    primes.Add(i);
                }

            res =rec(0, n/k);
            res = n/k - res;
            primes = new List<long>();
        }
        return res;
    }

    private long rec(int at, long n)
    {
        if (at >= primes.Count)
            return 0;
        if (n < primes[at])
            return 0;
        long res = n / primes[at];
        res+=rec(at+1,n);
        res -= rec(at + 1, n / primes[at]);
        return res;

    }

    bool prime(long p)
    {
        for (int i = 2; i * i <= p; i++)
            if (p % i == 0)
                return false;
        return true;
    }
    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        new Program().solve();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForces
{
    class Rook__Bishop_and_King
    {
        static void Main()
        {
            Run();
            Console.ReadLine();
        }
        static void Run()
        {
            string[] str = Console.ReadLine().Split();
            int r1 = int.Parse(str[0]);
            int c1 = int.Parse(str[1]);
            int r2 = int.Parse(str[2]);
            int c2 = int.Parse(str[3]);
            StringBuilder sb = new StringBuilder();
            if (r1 == r2 || c1 == c2)
            {
                sb.Append("1 ");
            }
            else
            {
                sb.Append("2 ");
            }
            if (r1 % 2 == 1)
            {
                if (c1 % 2 == 1)
                {
                    if (r2 % 2 == 0 && c2 % 2 == 0)
                    {
                        //reachable
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else if (r2 % 2 == 1 && c2 % 2 == 1)
                    {
                        //reachable
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else
                        sb.Append("0 ");
                }
                else
                {
                    if (r2 % 2 == 0 && c2 % 2 == 1)
                    {
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else if (r2 % 2 == 1 && c2 % 2 == 0)
                    {
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else
                    {
                        sb.Append("0 ");
                    }

                }
            }
            if (r1 % 2 == 0)
            {
                if (c1 % 2 == 1)
                {
                    if (r2 % 2 == 0 && c2 % 2 == 1)
                    {
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else if (r2 % 2 == 1 && c2 % 2 == 0)
                    {
                        //reachable
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else
                        sb.Append("0 ");
                }
                else
                {
                    if (r2 % 2 == 0 && c2 % 2 == 0)
                    {
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else if (r2 % 2 == 1 && c2 % 2 == 1)
                    {
                        if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                        {
                            sb.Append("1 ");
                        }
                        else
                        {
                            sb.Append("2 ");
                        }
                    }
                    else
                    {
                        sb.Append("0 ");
                    }

                }
            }
            if (r1 == r2)
            {
                sb.AppendFormat("{0} ", Math.Abs(c1 - c2));
            }
            else if (c1 == c2)
            {
                sb.AppendFormat("{0} ", Math.Abs(r1 - r2));
            }
            else
            {
                if (Math.Abs(r1 - r2) == Math.Abs(c1 - c2))
                {
                    sb.AppendFormat("{0} ", Math.Abs(c1 - c2));
                }
                else
                {

                    sb.AppendFormat("{0} ", Math.Max(Math.Abs(r1-r2) , Math.Abs(c1-c2)));

                }
            }
            Console.WriteLine(sb.ToString().Trim());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces217
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int r1 = int.Parse(input[0]),
                c1 = int.Parse(input[1]),
                r2 = int.Parse(input[2]),
                c2 = int.Parse(input[3]);

            if (r1 == r2 || c1 == c2)
                Console.Write("1 ");
            else Console.Write("2 ");

            if ((c1+r1) % 2 == (c2+r2)%2)
            {
                if (Math.Abs(r2 - r1) == Math.Abs(c2 - c1))
                    Console.Write("1 ");
                else Console.Write("2 ");
            }
            else Console.Write("0 ");

            Console.Write(Math.Max(Math.Abs(c2 - c1), Math.Abs(r2 - r1)));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForcesCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int x1, x2, y1, y2;

            int[] temp = Array.ConvertAll<string, int>(Console.ReadLine().Split(), Convert.ToInt32);
            x1 = temp[0];
            y1 = temp[1];
            x2 = temp[2];
            y2 = temp[3];

            int difX = Math.Abs(x2 - x1);
            int difY = Math.Abs(y2 - y1);

            if ((x1 == x2) || (y1 == y2)) Console.Write("1 ");
            else Console.Write("2 ");

            if (((x1 + y1) % 2) == ((x2 + y2) % 2))
            {
                if (difX == difY) Console.Write("1 ");
                else Console.Write("2 ");
            }
            else Console.Write("0 ");

            Console.WriteLine(Math.Max(difX, difY));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _217_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);
           int x1 = int.Parse(s[2]);
            int y1 = int.Parse(s[3]);
            int lengx = Math.Abs(x - x1);
            int lengy = Math.Abs(y - y1);
            int ans1=0;
            if (x == x1 && y == y1) { Console.WriteLine(0 + " " + 0 + " " + 0); return; }
            if (x == x1 || y == y1)
                ans1 = 1;
            else ans1 = 2;
            int ans2=0;
            if ((lengx + lengy) % 2 != 0) ans2 = 0;
            else
                if (lengx == lengy) ans2 = 1;
                else
                    ans2 = 2;
            int ans3 = 0;
            if (ans2 == 1) ans3 = lengy;
            else ans3 = Math.Max(lengy, lengx);
            Console.WriteLine(ans1+" "+ ans2+" "+ ans3);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Codeforces
{
	static class Program
	{
		static void Main(string[] args)
		{
			var rc = Console.ReadLine().Split().Select(int.Parse).ToList();
			var res = "";

			// rook
			if (rc[0] == rc[2] || rc[1] == rc[3]) res += "1 ";
			else res += "2 ";

			// bishop
			if ((rc[0] + rc[1]) % 2 == (rc[2] + rc[3]) % 2)
			{
				if (rc[0] + rc[1] == rc[2] + rc[3] || rc[0] - rc[1] == rc[2] - rc[3]) res += "1 ";
				else res += "2 ";
			}
			else res += "0 ";

			// king
			res += Math.Max(Math.Abs(rc[0] - rc[2]), Math.Abs(rc[1] - rc[3])).ToString();
			Console.WriteLine(res);
			Console.ReadLine();
		}

	}
}


//#define EXTENDSTACKSIZE

using System;
 using System.Collections.Generic;
 using System.Globalization;
using System.IO;
using System.Linq;
 using System.Text;
 using System.Threading;

         namespace CF
{
    internal class Program
    {
        private const int stackSize = 64 * 1024 * 1024;

        private static void Run()
        {
            using (var sr = new InputReader(Console.In))
//            using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
//            using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }

        private static void Main(string[] args)
        {
#if EXTENDSTACKSIZE
            var threadStart = new ThreadStart(Run);
            var thread = new Thread(threadStart, stackSize);
            thread.Start();
            thread.Join();
#else
            Run();
#endif
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var m = sr.NextInt32();
            var numbers = sr.ReadArrayOfInt32();
            var answ = new StringBuilder();
            answ.Append(0 + " ");
            for (var i = 1; i < n; i++)
            {
                var sum = numbers[i];
                var indx = 0;
                var sorted = new int[i];
                Array.Copy(numbers, sorted, i);
                Array.Sort(sorted);
                var j = 0;
                for (; j < i; j++)
                {
                    if (sum + sorted[j] > m)
                    {
                        break;
                    }

                    sum += sorted[j];
                }

                answ.Append((i - j) + " ");
            }

            sw.Write(answ);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      (var n, var M) = input.Read2Int();
      var t = input.ReadIntArray(n);
      var c = new int[101];
      var a = new int[n];
      var ss = 0;
      for (var i = 0; i < n; i++)
      {
        var j = 100;
        var s = ss;
        while (s > M - t[i] && j > 0)
        {
          var k = Min(c[j], (s - M + t[i] + j - 1) / j);
          s -= j * k;
          a[i] += k;
          j--;
        }
        ss += t[i];
        c[t[i]]++;
      }
      Write(string.Join(" ", a));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
      var result = (char)c - '0';
      c = reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
        result = result * 10 + (char)c - '0';
        c = reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() =>
      (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() =>
      (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() =>
      (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public (long, long) Read2Long() =>
      (ReadLong(), ReadLong());

    public (long, long, long) Read3Long() =>
      (ReadLong(), ReadLong(), ReadLong());

    public (long, long, long, long) Read4Long() =>
      (ReadLong(), ReadLong(), ReadLong(), ReadLong());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    long A, B;
    public void Solve()
    {
        var sc = new Scanner();
        A = sc.NextLong();
        B = sc.NextLong();
        var div = Div(A + B);
        var divA = Div(A);
        var divB = Div(B);
        div.Sort();
        divA.Sort();
        divB.Sort();
        long ans = long.MaxValue;
        for (int i = 0; i <= div.Count / 2; i++)
        {

            long j = div[div.Count - 1 - i];

            // A,Bのどちらかが i以下、j以下の積で表せるか?
            {
                int ok = -1;
                int ng = divA.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divA[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if(ok >= 0 && divA[divA.Count - ng] <= j)
                {
                    // Console.WriteLine($"A {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }

            {
                int ok = -1;
                int ng = divB.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divB[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if (ok >= 0 && divB[divB.Count - ng] <= j)
                {
                    // Console.WriteLine($"B {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }
        }
        Console.WriteLine(ans);
    }

    public List<long> Div(long l)
    {
        var result = new List<long>();
        for (long i = 1; i * i <= l; i++)
        {
            if (l % i == 0)
            {
                result.Add(i);
                if (l / i != i) result.Add(l / i);
            }
        }
        return result;
    }
    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


/*
csc -debug 1029_F.cs && mono --debug 1029_F.exe <<< "4 4"

a+b -> раскладываем на множители, начиная от sqrt(a+b) идем вниз -> так гаранируем min периметра. До x*y = a+b
a, b -> раскладываем на множители (начиная с маленького, учитывая 1,a), если хотя бы один из них раскладывается на два которые меньше x,y -> решение
*/

using System;
using System.Collections.Generic;
using System.Linq;

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
        // System.Console.WriteLine(PrimeHelpers.PollardRho(new Random(), 10967535067ul));
    }

    public static void SolveCodeForces() {
        var ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var a = ab[0];
        var b = ab[1];

        System.Console.WriteLine(Math.Min(Solve(a, b), Solve(b, a)));
    }

    public static long Solve(long a, long b) {
        var alowdivs = GetLowDivisors(a).ToArray();

        // System.Console.WriteLine(new {a, b});
        // System.Console.WriteLine("alowdivs = " + string.Join(" ", alowdivs));

        var p = long.MaxValue;

        foreach (var x in GetLowDivisors(a+b)) {
            var y = (a+b) / x;
            // a+b = xy,  x <= sqrt(a+b),  y >= sqrt(a+b)
            var i = BinarySearchRightmost(alowdivs, ad => ad - x);
            // System.Console.WriteLine(new { x, y, i });
            if ((i >= 0) && (a / alowdivs[i]) <= y) {
                // System.Console.WriteLine("Found a solution with perimeter " + (2L * (x + y)));
                p = Math.Min(p, 2L * (x + y));
            }
        }

        return p;
    }

    public static IEnumerable<long> GetLowDivisors(long x) {
        yield return 1L;
        if (x % 2L == 0) yield return 2L;

        var sqrt = Math.Sqrt(x);
        for (var d = 3L; d <= sqrt; d++)
            if (x % d == 0)
                yield return d;
    }

    private static int BinarySearchRightmost<T>(IList<T> arr, Func<T, long> compare) {
        var a = 0;
        var b = arr.Count;
        while (a < b) {
            var mid = (a + b) / 2;
            var cmp = compare(arr[mid]);

            if (cmp <= 0)
                a = mid + 1;
            else
                b = mid;
        }
        return a - 1;
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}