using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ARC069.C();
        }
        class ARC069
        {
            public static void C()
            {
                var N = Read.Long();
                var M = Read.Long();
                long scc1 = Math.Min(N, M / 2);
                long scc2 = (M - scc1 * 2) / 4;
                Console.WriteLine(scc1 + scc2);
            }
            public static void D()
            {
                var N = Read.Int();
                var S = Read.Str();

                Func<bool, bool, bool[]> func = (S0, S1) => {
                    var X = new bool[N];
                    X[0] = S0; X[1] = S1;
                    for(int i = 2; i < N; ++i)
                    {
                        X[i] = S[i - 1] == 'o' ^ X[i - 1] ^ X[i - 2];
                    }
                    if (X[0] != (S[N - 1] == 'o' ^ X[N - 1] ^ X[N - 2])) { return null; }
                    if (X[1] != (S[0] == 'o' ^ X[0] ^ X[N - 1])) { return null; }
                    return X;
                };
                var res = func(true, true);
                if (res == null) { res = func(true, false); }
                if (res == null) { res = func(false, true); }
                if (res == null) { res = func(false, false); }
                if (res == null) { Console.WriteLine(-1); return; }
                Console.WriteLine(String.Join("", res.Select(x => x ? "S" : "W")));
            }
            public static void E()
            {
                var N = Read.Int();
                var A = Read.LongN();
                List<long> list1 = new List<long>();
                List<int> list2 = new List<int>();
                long max = 0;
                for(int i = 0; i < N; ++i)
                {
                    if (A[i] > max)
                    {
                        list1.Add(A[i]);
                        list2.Add(i);
                        max = A[i];
                    }
                }
                long[] ans = new long[list1.Count];
                int[] count = new int[list1.Count];
                for(int i = 0; i < N; ++i)
                {
                    var a = A[i];
                    var idx = Bound.Lowerbound(list1, a);
                    if (list1[idx] < a)
                    {
                        ans[idx + 1] += a - list1[idx];
                    }
                    count[idx]++;
                }
                int cum = 0;
                for (int i = list1.Count - 1; i >= 0; --i)
                {
                    cum += count[i];
                    ans[i] += cum * (list1[i] - (i > 0 ? list1[i - 1] : 0));
                }
                var dict = new Dictionary<int, int>();
                for(int i = 0; i < list1.Count; ++i)
                {
                    dict.Add(list2[i], i);
                }
                var sb = new System.Text.StringBuilder();
                for(int i = 0; i < N; ++i)
                {
                    sb.AppendLine((dict.ContainsKey(i) ? ans[dict[i]] : 0).ToString());
                }
                Console.Write(sb.ToString());
            }
        }
        class Util
        {

        }
        class Bound
        {
            public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T>
            {
                int min = 0;
                int max = list.Count;
                while (min < max)
                {
                    var mid = (min + max) / 2;
                    if (list[mid].CompareTo(x) >= 0)
                    {
                        max = mid;
                    }
                    else
                    {
                        min = mid + 1;
                    }
                }
                return max;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN(); dict[ab[0]].Add(ab[1]);
                    if (!isDirectional) { dict[ab[1]].Add(ab[0]); }
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}


Measured memory_bytes: 11348