#include <iostream> using namespace std; int Euclid(int x, int y) { int r; while (y) { r=x%y; x=y; y=r; } return x; } int main() { long long a,b,dm=0, am,bm, gasit=0; cin>>a>>b; if (Euclid(a,b)==1) cout <<b-a+1; else { for (int i=1; i<4 && gasit==0; i++) { if (Euclid (a+i,b)==1) { dm=b-a-i+1; gasit=1; } } gasit=0; for (int i=1; i<4 && gasit==0; i++) { if (Euclid (a,b-i)==1) { if(dm>b-i-a+1) dm=b-i-a+1; gasit=1; } } cout<<dm; } return 0; }