#include <iostream>
using namespace std;
int main() {
int n, m, result = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (i * m + j == j * n + i) result++;
cout << result << "\n";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCkgewogIGludCBuLCBtLCByZXN1bHQgPSAwOwogIGNpbiA+PiBuID4+IG07CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCiAgICBmb3IgKGludCBqID0gMDsgaiA8IG07IGorKykKICAgICAgaWYgKGkgKiBtICsgaiA9PSBqICogbiArIGkpIHJlc3VsdCsrOwogIGNvdXQgPDwgcmVzdWx0IDw8ICJcbiI7Cn0=