#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pll pair<long long, long long>
#define pii pair<int, int>
#define mii map <int , int>
#define mll map <long long ,long long>
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cmp greater<int>()
#define RF(F) freopen(F , "r" , stdin )
#define WF(F) freopen(F , "w" , stdout)
using namespace std;
const ll INF = 1e9 ;
const int N = 500 + 7 ;
const int mod = 1e9 + 7;
int mem[N][N] ;
string get_string() {
const int N = 2e5 + 7 ;
char s[N] ;
scanf("%s" , s) ;
return s ;
}
void init() {
memset(mem , -1 , sizeof mem) ;
}
int dp(int n , int m){
if(n == m)return 0 ;
if(m == 1)return n - 1 ;
if(n == 1)return m - 1 ;
if(mem[n][m] != -1)return mem[n][m] ;
int ans = INF ;
for(int i = 1 ; i <= (n / 2) ; i ++){
ans = min(ans , 1 + dp(i , m) + dp(n - i , m)) ;
}
for(int j = 1 ; j <= (m / 2) ; j ++){
ans = min(ans , 1 + dp(n , j) + dp(n , m - j)) ;
}
return mem[n][m] = ans ;
}
void solve(int testCase){
int n , m ;
scanf("%d %d" , &n , &m) ;
printf("%d" , dp(n , m)) ;
}
int main() {
int testCase = 1;
//scanf("%d", &testCase);
while (testCase--){
init();
solve(testCase);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCiNkZWZpbmUgcGxsIHBhaXI8bG9uZyBsb25nLCBsb25nIGxvbmc+CiNkZWZpbmUgcGlpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgbWlpIG1hcCA8aW50ICwgaW50PgojZGVmaW5lIG1sbCBtYXAgPGxvbmcgbG9uZyAsbG9uZyBsb25nPgojZGVmaW5lIHZpIHZlY3RvciA8aW50PgojZGVmaW5lIHZsIHZlY3RvciA8bG9uZyBsb25nPgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIElPUyBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiNkZWZpbmUgY21wIGdyZWF0ZXI8aW50PigpCiNkZWZpbmUgUkYoRikgZnJlb3BlbihGICwgInIiICwgc3RkaW4gKSAKI2RlZmluZSBXRihGKSBmcmVvcGVuKEYgLCAidyIgLCBzdGRvdXQpIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmNvbnN0IGxsIElORiA9IDFlOSA7CmNvbnN0IGludCBOID0gNTAwICsgNyA7CmNvbnN0IGludCBtb2QgPSAxZTkgKyA3OwppbnQgbWVtW05dW05dIDsKIApzdHJpbmcgZ2V0X3N0cmluZygpIHsKIAogICAgY29uc3QgaW50IE4gPSAyZTUgKyA3IDsKICAgIGNoYXIgc1tOXSA7CiAKICAgIHNjYW5mKCIlcyIgLCBzKSA7CiAKICAgIHJldHVybiBzIDsKfQogCnZvaWQgaW5pdCgpIHsKICAgIG1lbXNldChtZW0gLCAtMSAsIHNpemVvZiBtZW0pIDsKfQogCmludCBkcChpbnQgbiAsIGludCBtKXsKIAogICAgaWYobiA9PSBtKXJldHVybiAwIDsKIAogICAgaWYobSA9PSAxKXJldHVybiBuIC0gMSA7IAogCiAgICBpZihuID09IDEpcmV0dXJuIG0gLSAxIDsKIAogICAgaWYobWVtW25dW21dICE9IC0xKXJldHVybiBtZW1bbl1bbV0gOwogCiAgICBpbnQgYW5zID0gSU5GIDsKIAogICAgZm9yKGludCBpID0gMSA7IGkgPD0gKG4gLyAyKSA7IGkgKyspewogICAgICAgIGFucyA9IG1pbihhbnMgLCAxICsgZHAoaSAsIG0pICsgZHAobiAtIGkgLCBtKSkgOwogICAgfQogICAgZm9yKGludCBqID0gMSA7IGogPD0gKG0gLyAyKSA7IGogKyspewogICAgICAgIGFucyA9IG1pbihhbnMgLCAxICsgZHAobiAsIGopICsgZHAobiAsIG0gLSBqKSkgOwogICAgfQogCiAgICByZXR1cm4gbWVtW25dW21dID0gYW5zIDsKfQogCnZvaWQgc29sdmUoaW50IHRlc3RDYXNlKXsKIAogICAgaW50IG4gLCBtIDsKICAgIHNjYW5mKCIlZCAlZCIgLCAmbiAsICZtKSA7CiAKICAgIHByaW50ZigiJWQiICwgZHAobiAsIG0pKSA7Cn0KIAppbnQgbWFpbigpIHsKIAogICAgaW50IHRlc3RDYXNlID0gMTsKIAogICAgLy9zY2FuZigiJWQiLCAmdGVzdENhc2UpOwogCiAgICB3aGlsZSAodGVzdENhc2UtLSl7CiAgICAgICAgaW5pdCgpOwogICAgICAgIHNvbHZlKHRlc3RDYXNlKTsKICAgIH0KIAogICAgcmV0dXJuIDA7Cn0=