#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef int li;
typedef long double lf;
inline li read(){
li ans = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
f = (ch == '-') ? -1 : 1;
ch = getchar();
}
while(ch <= '9' && ch >= '0'){
ans = ans * 10 + (ch ^ 48);
ch = getchar();
}
return ans * f;
}
li n, m, maxn;
__gnu_pbds::gp_hash_table<long long, li> mp;
//struct hash_table{
// li head[(int)1e7 + 12], next[int(5e7) + 9], lenp;
// long long val[(int)5e7 + 9];
// const li mod = 1e7 + 9;
// li query(long long x){
//// cout << x << endl;
// li p = x % mod;
// for(li i = head[p]; i; i = next[i]){
// if(val[i] == x) return 1;
// }
//// cout << x << endl;
// next[++lenp] = head[p];
// val[lenp] = x;
// head[p] = lenp;
// return 0;
// }
//} mp;
li ans;
queue<pair<li, li>> qu;
void dfs(li p, li q, li op){
// cout << p << " " << q << endl;
// if(mp[p * 1000000000ll + q]) return;
// mp[p * 1000000000ll + q] = 1;
// cout << p << " " << q << endl;
// if(mp[p * 1000000000 + q]) return;
// mp[p * 1000000000 + q] = 1;
if(p <= n && q <= m) ans++;
// if(ans % 10000)
if(1 <= q && q <= maxn && 1 <= p && p <= maxn && !op) dfs(q, p, 1);
// if(p > 2 * q) dfs(p - 2 * q, q);
if(p + 2 * q <= maxn) dfs(p + 2 * q, q, 0);
}
int main(){
// freopen("wonderful.ans", "r", stdin);
// freopen("www.ww", "w", stdout);
// double begin = clock();
// mp.lenp = 0;
n = read(), m = read();
maxn = max(n, m);
dfs(1, 2, 0);
// qu.push({1, 2});
// mp.query(1 * 1000000000ll + 2);
// while(!qu.empty()){
// li p = qu.front().first, q = qu.front().second;
// if(p <= n && q <= m) ans++;
// qu.pop();
//// cout << p << " " << q << endl;
// if(1 <= q && q <= maxn && 1 <= p && p <= maxn){
// if(!mp.query(q * 1000000000ll + p)) qu.push({q, p});
// }
// if(p > 2 * q){
// if(!mp.query((p - 2 * q) * 1000000000ll + q)) qu.push({p - 2 * q, q});
// }
// if(p + 2 * q <= maxn){
// if(!mp.query((p + 2 * q) * 1000000000ll + q)) qu.push({p + 2 * q, q});
// }
// }
printf("%d\n", ans);
printf("%.4Lf s\n", (lf)(clock() - (lf)begin) / (lf)CLOCKS_PER_SEC);
return 0;
}