A and B are preparing themselves for programming contests.

An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.

A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.

However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.

As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.

There are *n* experienced members and *m* newbies on the training session. Can you calculate what maximum number of teams can be formed?
The first line contains two integers *n* and *m* (0 ≤ *n*, *m* ≤ 5·10<sup class="upper-index">5</sup>) — the number of experienced participants and newbies that are present at the training session.
import os
import sys
import time
import math as mt
import pprint
import itertools as it
import operator as op
import bisect as bs
import functools as fn
import queue
from collections import deque, defaultdict , OrderedDict, Counter, ChainMap
maxx, localsys, mod = 1 << 60, 0, int(1e9 + 7)
def nCr(n, r): return reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)


def ceil(n, x): return (n + x - 1) // x


osi, oso = '/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt'
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')

input = sys.stdin.readline

def maps(): return map(int, input().split())

#   THINK ABOUT THE EDGE CASES ..........

#   DON'T SUBMIT UNLESS YOU ARE ABSOLUTELY SURE !!!!!

def Kth_beautiful_string():
	for _ in range(int(input())):
		n , k = maps() ; arr = ['a']*n
		for i in range(n-1 , -1 , -1):
			if n-i-1 >= k:
				arr[i]=  arr[i + (n-i-1) - (k-1)] ='b'
				print(''.join(arr)) ; break
			k-=n-i-1
	#constantly decrease the number of string whose left most position is at i,because at every ith position (n-i-1) strings exists whose right most position is at i
def subhate():
	for _ in range(*maps()):
		s = input().rstrip('\n')
		s1 , s0 = 0 , 0
		for i in s:
			s1 += (i == '1') ; s0 += (i == '0')
		p1 , p0 = 0,0
		ans = maxx
		for i in s:
			p1 += (i == '1') ;p0 += (i == '0') ;s1 -= (i == '1') ; s0 -= (i == '0')
			ans = min(ans , (p1+s0) , (p0 + s1))
		print(ans)
		#convert the string into 0000....1111 or 11111....00000
def pair_of_topics():
	n, = maps()
	a ,b  = [*maps()] , [*maps()]
	ans =0
	c = sorted(a[i]-b[i] for i in range(n))
	for i in range(n):
		ans += max(i - bs.bisect_right(c , -c[i]),0)
	print(ans)
	#the i <j is given , so you don't count (1 , 2) and (2 ,1 ) as different pairs
def search(arr , key):
	l , h = 0 , len(arr) - 1
	idx= -1
	while l<=h:
		m = (l+h)//2
		if arr[m] == key:
			return m
		elif arr[m] < key:
			l = m + 1
		else:
			idx =m
			h = m - 1
	return idx


def zero_remainder_array():
	for _ in range(*maps()):
		n , k = maps()
		a = [*maps()]
		ans , cnt = 0 , defaultdict(int)
		for i in a:
			if i % k :
				cnt[i%k]+=1
				ans = max(ans , k*cnt[i%k] - i%k + 1)
		print(ans)


def A_B():
	def naive(n , m):
		ans = 0
		while n >0 and m >0:
			if n >=m:
				if n -2 >=0 and m-1 >=0:
					n-=2
					m-=1
					ans+=1
				else:
					break
			else:
				if m -2 >=0 and n -1 >=0:
					m-=2
					n-=1
					ans+=1
				else:
					break
		return ans

	n , m = maps()
	t = naive(n,m)
	N , M = n , m
	ans = 0
	while abs(n-m)>=1 and (n+m)>=3 and ((n>=2 and m>=1) or (m>=2 and n >=1)):
		if n >=m:
			diff = min(m,(n - m))
			n-=2*diff
			m-=diff
		else:
			diff = min(n,(m - n))
			m-= 2*diff
			n-= diff
		ans+=diff
	if n == m:
		x = max(0, (n//3) -1)
		ans += x*2
		n-=3*x
		m-=3*x
	ans+= naive(n,m)
	# if n >=m:
	# 	x=  min(n//2 , m)
	# 	ans+=x
	# 	n-= 2*x
	# 	m-=x
	# else:
	# 	x = min(m//2 , n)
	# 	ans+=x
	# 	m-= 2*x
	# 	n-=x

	# print(ans , t,n,m)

	# if n >=2 and m >=1:
	# 	x+=min(n//2 ,m)

	# elif m >=2 and n >=1:
	# 	x += min(m//2 , n)

	# if ans != t:
	# 	print(ans,t , N,M)
	print(ans)

# for _ in range(*maps()):
A_B()