#include <fstream>
using namespace std;
int main()
{
    ifstream f1("TUOI.inp");
    ofstream f2("TUOI.out");
    int a,b,i = 0;
    f1 >> a >> b;
    f1.close();
    while (a > (b * 2))
    {
            a = a + 1;
            b = b + 1;
            i = i + 1;
    }
    if (a == b * 2) f2 << i;
    else f2 << "-1";
    f2.close();
    return 0;
}
