#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x = 1;
int shape1[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
shape1[i][j] = x;
x++;
}
}
int y=1;
int shape2[m][n];
for(int j=0; j<m; j++){
for(int i=0; i<n; i++){
shape2[i][j] = y;
y++;
}
}
int k = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(shape1[i][j] == shape2[i][j])
k++;
}
}
cout << k;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbiwgbTsKCWNpbiA+PiBuID4+IG07CglpbnQgeCA9IDE7CglpbnQgc2hhcGUxW25dW21dOwoJZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKCQlmb3IoaW50IGo9MDsgajxtOyBqKyspewoJCQlzaGFwZTFbaV1bal0gPSB4OwoJCQl4Kys7CgkJfQoJfQoJCglpbnQgeT0xOwoJaW50IHNoYXBlMlttXVtuXTsKCWZvcihpbnQgaj0wOyBqPG07IGorKyl7CgkJZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKCQkJc2hhcGUyW2ldW2pdID0geTsKCQkJeSsrOwoJCX0KCX0KCQoJaW50IGsgPSAwOwoJZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKCQlmb3IoaW50IGo9MDsgajxtOyBqKyspewoJCQlpZihzaGFwZTFbaV1bal0gPT0gc2hhcGUyW2ldW2pdKQoJCQkJaysrOwoJCX0KCX0KCQoJY291dCA8PCBrOwoJcmV0dXJuIDA7Cn0=