#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)

ll a2, a1, b2, b1;

void step1(){
  // 相手をできるだけ減らさない
  ll pls = a2 + a1;
  ll sb = min(b2, pls);
  pls -= sb;
  b2 -= sb;
  b1 += sb;
  sb = min(b1, pls);
  pls -= sb;
  b1 -= sb;
  swap(a1,b1);swap(a2,b2);
}
void step2(){
  // 相手をできるだけ減らす
  ll pls = a2 + a1;
  if(pls>0 && b1>0){
    b1--;pls--;
  }
  ll sb = min(b2, pls/2);
  pls -= sb*2;
  b2 -= sb;
  if(pls>0 && b2>0){
    pls--;
    b2--;
    b1++;
  }
  swap(a1,b1);swap(a2,b2);
}

int main(){
  ll n,m;
  cin>>n>>m;
  ll ans = max(n,m)*2ll;
  {
    a2=n,a1=0,b2=m,b1=0;
    ll tmp = 0;
    while(true){
      step1();
      if(a1+a2==0)break;
      tmp++;
      step2();
      if(a1+a2==0)break;
      tmp++;
    }
    ans = min(ans,tmp);
  }
  {
    a2=n,a1=0,b2=m,b1=0;
    ll tmp = 0;
    while(true){
      step2();
      if(a1+a2==0)break;
      tmp++;
      step1();
      if(a1+a2==0)break;
      tmp++;
    }
    ans = min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}
