#include <stdio.h>
bool b[100000];
int min(int a, int b)
{
    if (a < b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int main()
{
    int n, m, j = 0, max = 0;
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= m; i++)
        for (int j = 0; j <= n; j++)
        {
            if (i * n + j * m >= 100000)
                break;
            b[i * n + j * m] = true;
        }
    for (int i = min(m, n); i <= n * m; i++)
    {
        if (b[i])
        {
            j++;
            if (j == min(m, n))
            {
                printf("%d", max);
                break;
            }
        }
        else
        {
            max = i;
            j = 0;
        }
    }
}