#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include<stdio.h> #include<string.h> #include<vector> #include<algorithm> #include<cmath> #include<map> #include<queue> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1 | 1 #define lowbit(x) x&(-x) using namespace std; const int N=1e5+10; long long INF=-1e15; int T,n,m,k; const int MOD=1e9+7; long long ans; void dfs(long long l,long long r){ if(ans && r>ans) return; if(l<1) return; if(l==1){ if(ans) ans=min(ans,r); else ans=r; return; } if(2*l<r+2) return; int m=r-l+1; if(l-m-1>0) dfs(l-m-1,r); dfs(l-m,r); dfs(l,r+m); if(m>1) dfs(l,r+m-1); } int main() { #ifndef ONLINE_JUDGE freopen("aaa","r",stdin); #endif int T; int L,R; while(~scanf("%d%d",&L,&R)){ ans=0; L++;R++; dfs(L,R); if(0==ans) ans=-1; else ans--; printf("%I64d\n",ans); } return 0; }