#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#define SIZE 105

using namespace std;

/* Name are to be changed before sending code/ */

ifstream f("date.in");
ofstream g("date.out");

int     n, m, x;

void    prel_1(void)
{
    int     a[SIZE][SIZE];

    cin >> n >> m >> x;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int row = 1; row <= x; row++)
        {
            for (int j = 1; j <= m; j++)
            {
                for (int col = 1; col <= x; col++)
                    cout << a[i][j] << ' ';
            }
            cout << '\n';
        }
    }
}

unsigned long long     cmmdc(unsigned long long a, unsigned long long b)
{
    unsigned long long c;

    while (b)
    {
        c = a % b;
        a = b;
        b = c;
    }
    return (a);
}

void    prel_3(void)
{
    long long a, b;

    cin >> a >> b;
    if (cmmdc(a, b) == 1)
    {
        cout << b - a + 1;
        return ;
    }
    if (a % 2 == 0 && b % 2 == 0)
    {
        a++;
        b--;
    }
    if (a % 2 || b % 2 )
    {
        if (a % 2 == 1)
        {
            if (cmmdc(a, b) == 1)
            {
                cout << b - a + 1;
                return ;
            }
            else
                b--;
        }
        else if (b % 2 == 1)
        {
            if (cmmdc(a, b) == 1)
            {
                cout << b - a + 1;
                return ;
            }
            else
                a++;
        }
    }
    while (a < b)
    {
        if (cmmdc(a, b) == 1)
        {
            cout << b - a + 1;
            return ;
        }
        a += 2;
        b -= 2;
    }
}

int main()
{
    prel_3();
    return 0;
}