using System;

namespace _a
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long[] Arr = new long[14];
            string[] Input = Console.ReadLine().Split();
            for (int i = 0; i < 14; i++) Arr[i] = Convert.ToInt64(Input[i]);

            long Max = 0;
            for (int i = 0; i < 14; i++)
            {
                if (Arr[i] != 0)
                {
                    long[] ArrW = new long[14];
                    Array.Copy(Arr, ArrW, 14);
                    long K = ArrW[i % 14] % 14;
                    long T = ArrW[i % 14];
                    ArrW[i % 14] = 0;
                    for (int j = 0; j < 14; j++)
                    {
                        ArrW[(i + j + 1) % 14] += T / 14 ;
                    }

                    for (int j = 1; j <= K; j++)
                    {
                        ArrW[(i + j) % 14]++;
                    }

                    long Res = 0;
                    for (int j = 0; j < 14; j++)
                    {
                        if (ArrW[j] % 2 == 0)
                        {
                            Res += ArrW[j];
                        }
                    }

                    if (Res > Max) Max = Res;
                }
            }

            Console.WriteLine(Max);
        }
    }
}


#define EXTENDSTACKSIZE

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

namespace CF
{
    internal class Program
    {
        private const int stackSize = 64 * 1024 * 1024;

        private static void Run()
        {
            using (var sr = new InputReader(Console.In))
//            using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
//            using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }

        private static void Main(string[] args)
        {
#if EXTENDSTACKSIZE
            var threadStart = new ThreadStart(Run);
            var thread = new Thread(threadStart, stackSize);
            thread.Start();
            thread.Join();
#else
            Run();
#endif
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            var s1 = sr.NextString().Split(new[] {':'});
            var h1 = int.Parse(s1[0]);
            var m1 = int.Parse(s1[1]);
            var s2 = sr.NextString().Split(new[] {':'});
            var h2 = int.Parse(s2[0]);
            var m2 = int.Parse(s2[1]);
            var d1 = new DateTime(1, 1, 1, h1, m1, 0);
            var d2 = new DateTime(1, 1, 1, h2, m2, 0);
            var d = (d2 - d1).Ticks / 2;
            var d3 = d1.AddTicks(d);
            var h = d3.Hour.ToString();
            var m = d3.Minute.ToString();
            if (h.Length == 1)
            {
                h = "0" + h;
            }

            if (m.Length == 1)
            {
                m = "0" + m;
            }
            sw.WriteLine(h + ":" + m);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


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

namespace Task1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> time0 = Console.ReadLine().Split(':').ToList().ConvertAll(int.Parse);
            int minutsBegin = 60 * time0[0] + time0[1];
            List<int> timeK = Console.ReadLine().Split(':').ToList().ConvertAll(int.Parse);
            int minutsEnd = 60 * timeK[0] + timeK[1];
            int minuteAverage = (minutsBegin + minutsEnd) / 2;
            int hourEnd = minuteAverage / 60;
            int minuteEnd = minuteAverage % 60;
            Console.WriteLine(String.Format("{0:00}", hourEnd)+":"+ String.Format("{0:00}", minuteEnd));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication15
{
    class Program
    {
        static int Main(string[] args)
        {
            string[] inArr = Console.ReadLine().Split(' ');
            int n = int.Parse(inArr[0]),
                m = int.Parse(inArr[1]);
            int[] originalArr = new int[n];
            for (int i = 0; i < n; i++)
                originalArr[i] = i + 1;
            string[] allArrays= new string[factorial(n)];
            for (int i=0; i<factorial(n); i++)
            {
                allArrays[i] = getNumbers(originalArr, i);
            }
            int[] allFp = new int[allArrays.Length];
            int maxFp = 0;
            for (int cur = 0; cur < allArrays.Length; cur++)
            {
                int fP = 0;
                string[] p = allArrays[cur].Split(' ');
                for (int i = 0; i < n; i++)
                {
                    for (int j = i; j < n; j++)
                    {
                        int min = int.Parse(p[i]);
                        for (int x = i; x <= j; x++)
                        {
                            if (int.Parse(p[x]) < min)
                                min = int.Parse(p[x]);
                        }
                        fP += min;
                    }
                }
                allFp[cur] = fP;
                if (fP > maxFp) maxFp = fP;
            }
            int curM = 1;
            for (int i = 0; i < allArrays.Length; i++)
            {
                if (allFp[i] == maxFp)
                {

                    if (curM == m)
                    {
                        Console.Write(allArrays[i]);
                        break;
                    }
                    curM++;
                }
            }
            return 0;
        }
        static string getNumbers(int[] nums, long cur)
        {

            int size = nums.Length;
            if (size == 1) return Convert.ToString(nums[0]);
            long amount = factorial(size);
            long ind = (long)(cur / (amount / size));
            int[] newNums = new int[size - 1];
            int Tx = 0;
            for (int x = 0; x < size; x++)
            {
                if (x == ind)
                    continue;
                newNums[Tx] = nums[x];
                Tx++;
            }
            return nums[ind] + " " + getNumbers(newNums, (cur - (amount / size) * ind));

        }
        static long factorial(int n)
        {
            return n <= 1 ? 1 : n * factorial(n - 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RocketB
{
    class Program
    {

        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            var strs = str.Split(' ');
            int n = 0;
            long m = 0;
            int.TryParse(strs[0], out n);
            long.TryParse(strs[1], out m);
            --m;

            int[] array = new int[n];

            var tempm = m;
            for (int i = 0; i < n; i++)
            {
                array[i] = (int)(tempm % 2);
                tempm /= 2;
            }

            for (int i = 0; i < n - 1; i ++)
            {
                if (array[n - 1 - i - 1] == 0)
                {
                    Console.Write(i + 1);
                    Console.Write(" ");
                }
                else
                {
                    //Console.Write(i + 1 );
                    //Console.Write(" ");
                }

            }

           // if (p2 > 0)
            {
                Console.Write(n - 1 + 1 );
                Console.Write(" ");
            }

            for (int i = n - 2; i >= 0; i--)
            {
                if (array[n - 1 - i -1] == 0)
                {
                    //Console.Write(i + 1);
                    //Console.Write(" ");
                }
                else
                {
                    Console.Write(i + 1);
                    Console.Write(" ");
                }

            }
            Console.WriteLine("");

        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace olimp
{

    class Node
    {
        public List<Node> Roads;
        public List<Node> ClosedRoads;
        public int Id,Mark;
    }

    static class Program
    {
        private static void Main()
        {
            string[] s =  Console.ReadLine().Split(' ');
            int[] a = new[]{ int.Parse(s[0]), int.Parse(s[1]), int.Parse(s[2]) };
            Array.Sort(a);
            int r, g, b;
            r = a[0];
            g = a[1];
            b = a[2];
            int ans = r + (g-r)/3 + (b-r)/3;
            int ans2 = b / 3 + g / 3 + Math.Min(r, Math.Min(b % 3, g % 3)) + (r - Math.Min(r, Math.Min(b % 3, g % 3)))/3;
            ans = Math.Max(ans, ans2);
            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static void ReadIntPair(out int a1, out int a2)
        {
            string[] s = Console.ReadLine().Split(' ');
            a1 = int.Parse(s[0]);
            a2 = int.Parse(s[1]);
        }

        static long ReadNextInt()
        {
            char c;
            StringBuilder builder = new StringBuilder(4);
            while (char.IsDigit(c = (char) Console.Read()) || c == '-'||c == '\r' || c == '\n')
            {
                if (c == '\r' || c == '\n')
                    continue;
                builder.Append(c);
            }
            return long.Parse(builder.ToString());
        }

        static int Sum1(int n)
        {
            int sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += (int)(Math.Pow(-1, i)*Math.Pow(n - i, 2));
            }
            return sum;
        }

        static int Sum2(int n)
        {
            return (n*(n+1))/2;
        }

        static double Log10(double x)
        {
            int n = CalnN((int) x);
            double val = n;
            double last = x;
            for (int i = 1; i <= sizeof(double) * 8; i++)
            {
                last = last*last;
                if (last >= 10)
                {
                    val += 1/Math.Pow(2, i);
                    last /= 10;
                }
            }
            return val;
        }

        static int CalnN(int x)
        {
            int i = 0;
            for (; Math.Pow(x, i + 1) < x; i++)
            {
            }
            return i;
        }
    }
}


using System;

namespace Flowers
{
    class Flowers
    {
        static void Main(string[] args)
        {
            string[] rgb = Console.ReadLine().Split(' ');
            long r = long.Parse(rgb[0]);
            long g = long.Parse(rgb[1]);
            long b = long.Parse(rgb[2]);

            long rm = r % 3;
            long gm = g % 3;
            long bm = b % 3;
            if (rm == 0 && r > 0) rm = 3;
            if (gm == 0 && g > 0) gm = 3;
            if (bm == 0 && b > 0) bm = 3;

            long f = (r - rm) / 3 + (g - gm) / 3 + (b - bm) / 3;

            long min = Math.Min(rm, Math.Min(bm, gm));
            long thr = (rm == 3 ? 1 : 0) + (gm == 3 ? 1 : 0) + (bm == 3 ? 1 : 0);
            f += Math.Max(min, thr);

            Console.WriteLine(f);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public static string Check(string s)
        {
            string letters = "aeiouy";

            while (true)
            {
                bool used = false;

                for (int i = 0; i < s.Length - 1; i++)
                {
                    if (letters.Contains(s[i].ToString()) && letters.Contains(s[i + 1].ToString()))
                    {
                        s = s.Remove(i + 1, 1);

                        used = true;
                    }
                }

                if (!used)
                {
                    return s;
                }
            }
        }

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int p = a[0];
            int y = a[1];

            for (int i = y; i > p; i--)
            {
                bool ok = true;

                for (int j = 2; j <= p && j * j <= i; j++)
                {
                    if (i % j == 0)
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine(-1);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}


using System;

namespace CSharp
{
    class _937B
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int p = int.Parse(tokens[0]);
            int y = int.Parse(tokens[1]);

            for (; y > p; y--)
            {
                bool suitable = true;

                for (int i = 2; i <= p && i <= y / i; i++)
                {
                    if (y % i == 0)
                    {
                        suitable = false;
                        break;
                    }
                }

                if (suitable)
                {
                    Console.WriteLine(y);
                    return;
                }
            }

            Console.WriteLine(-1);
        }
    }
}


/*
csc -debug B.cs && mono --debug B.exe <<< "6
5 10 2 3 14 5"
*/

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var sc = new Scanner();

        var n = sc.NextInt();
        var A = sc.UlongArray().OrderBy(a => a).ToArray();

        var cnt = 0ul;
        for (var i = 0; i < n/2; i++) {
            cnt += A[2*i+1] - A[2*i];
        }

        System.Console.WriteLine(cnt);
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static T ElementWithMax<T>(this IEnumerable<T> seq, Func<T, long> func) {
        var bi = default(T);
        var bv = long.MinValue;
        foreach (var item in seq) {
            var v = func(item);
            if (v > bv) {
                bi = item;
                bv = v;
            }
        }
        return bi;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray() {
        var array = Array();
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Graph
{
    public class Program
    {
        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader("in.txt"));
            Console.SetOut(new StreamWriter("out.txt") { AutoFlush = true });
#endif
            var n = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToList();

            array.Sort();

            int result = 0;
            for (int i = 0; i < n; i+=2)
            {
                result += array[i + 1] - array[i];
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;

class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		Dictionary<int, int> a = new Dictionary<int, int>();
		for (int i = 1; i <= 5; i++)
		{
			a[i] = 0;
		}
		string s = Console.ReadLine();
		for (int i = 0; i < s.Length; i += 2)
		{
			a[int.Parse(s[i].ToString())]++;
		}
		Dictionary<int, int> b = new Dictionary<int, int>();
		for (int i = 1; i <= 5; i++)
		{
			b[i] = 0;
		}
		s = Console.ReadLine();
		for (int i = 0; i < s.Length; i += 2)
		{
			b[int.Parse(s[i].ToString())]++;
		}
		int counter = 0;
		for (int i = 1; i <= 5; i++)
		{
			if ((a[i] + b[i]) % 2 == 0)
			{
				if (a[i] > b[i])
				{
					counter += (a[i] - b[i]) / 2;
				}
			}
			else
			{
				Console.WriteLine("-1");
				return;
			}
		}
		Console.WriteLine(counter);
	}
}


using System;
using System.Linq;

static class P {
    static int[] ToIntArray(this string s) { return s.Split().Select(int.Parse).ToArray(); }
    static void Main() {
        int n = int.Parse(Console.ReadLine()), r = 0;
        int[] A = Console.ReadLine().ToIntArray(),
            B = Console.ReadLine().ToIntArray();

        var all = A.Concat(B).GroupBy(x => x)
            .Select(x => new { Key = x.Key, Count = x.Count() });

        foreach (var info in all) {
            if (info.Count % 2 != 0) {
                Console.WriteLine(-1);
                return;
            }
        }

        var grA = A.GroupBy(x => x)
            .Select(x => new { Key = x.Key, Count = x.Count() });

        foreach (var info in all) {
            var val = info.Count / 2;
            var found = grA.FirstOrDefault(x => x.Key == info.Key);

            if (found != null) {
                if (found.Count > val) {
                    r += found.Count - val;
                }
            }
        }

        Console.WriteLine(r);
    }
}


using System;

namespace ConsoleApplication2
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string a = Console.ReadLine();
            int end = 0;;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == '+')
                {
                    end++;
                }
                else
                {
                    end--;
                }

                if (end < 0)
                {
                    end++;
                }
            }

            int s = end;
            Console.WriteLine(s);
            Console.ReadLine();
        }
    }
}


// Problem: 1159A - A pile of stones
// Author: Gusztav Szmolik

using System;

class APileOfStones
    {
    public static int Main ()
        {
        string line = Console.ReadLine ();
        if (line == null)
            return -1;
        string[] words = line.Split ();
        if (words.Length != 1)
            return -1;
        byte n;
        if (!Byte.TryParse (words[0], out n))
            return -1;
        if (n < 1 || n > 100)
            return -1;
        line = Console.ReadLine ();
        if (line == null)
            return -1;
        words = line.Split ();
        if (words.Length != 1)
            return -1;
        string s = words[0];
        if (s.Length != n)
            return -1;
        byte ans = 0;
        char c;
        for (byte i = 0; i < n; i++)
            {
            c = s[i];
            if (c != '-' && c != '+')
                return -1;
            if (c == '-' && ans > 0)
                ans--;
            else if (c == '+')
                ans++;
            }
        Console.WriteLine (ans);
        return 0;
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaskB
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine().Split('e');
            string a = input[0];
            string exp = input[1];
            int b = int.Parse(exp);

            if (a == "0.0")
            {
                Console.WriteLine(0);
                return;
            }

            if (a.First() == '0')
            {
                Console.WriteLine(a);
                return;
            }

            int pointIndex = a.IndexOf('.');

            if (b == 0)
            {
                if (a.Length - (pointIndex + 1) == 1 && a.Last() == '0')
                {
                    Console.WriteLine(a.Substring(0, pointIndex));
                    return;
                }
            }

            if (pointIndex != -1)
            {

                a = a.Remove(pointIndex, 1);
                if (pointIndex + b < a.Length)
                {
                    pointIndex += b;
                    a = a.Insert(pointIndex, ".");
                }
                else
                {
                    int extend = pointIndex + b - a.Length;
                    if ( extend > 0)
                    {
                        char[] zero = new char[extend];
                        for (int i = 0; i < extend; i++)
			            {
			                zero[i] = '0';
			            }

                        a += new string(zero);
                    }
                }

            Console.WriteLine(a);
            Console.ReadLine();
            }
        }
    }
}


using System;

class Round362P2{
	static string StripFrontZero(string str){
		string ret = "";
		bool fl = true;
		for(int i=0;i<str.Length;i++){
			if(fl && str[i] == '0')
				continue;
			if(str[i] != '0'){
				fl = false;
			}
			if(!fl){
				ret += str[i];
			}
		}
		return ret;
	}
	public static void Main(string[] args){
		string line = Console.ReadLine();
		string bd = "",ad = "" ,pow = "";
		bool dfl = false;
		bool efl = false;
		int ipow = 0;
		for(int i=0;i<line.Length;i++){
			if(line[i] == '.'){
				dfl = true;
				continue;
			}
			if(line[i] == 'e'){
				efl = true;
				continue;
			}
			if(dfl == false){
				bd += line[i];
			}
			else if(dfl == true && efl == false){
				ad += line[i];
			}
			else if(dfl == true && efl == true){
				pow += line[i];
				ipow = ipow*10+(int)line[i]-48;
			}
		}
		string nad = "";
		//not int
		if(ipow < ad.Length){
			nad = ad.Substring(0,ipow)+"."+ad.Substring(ipow,ad.Length-ipow);
			//Console.WriteLine("nad: "+nad);
		}
		else{
			nad = ad;
			for(int i=0;i<ipow - ad.Length;i++)
				nad += "0";
		}
		string ans = "";
		if(nad.CompareTo(".0") == 0){
			ans = bd;
		}
		else if(bd.CompareTo("0") != 0){
			ans  = bd+nad;
		}
		else{
			string temp = StripFrontZero(nad);
			if(temp[0] == '.')
				ans = '0'+temp;
			else ans  = temp;
		}
		Console.WriteLine(ans);
	}
}


using System;
using System.Linq;

namespace CSharp
{
    class _17A
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int k = int.Parse(tokens[1]);

            var isPrime = new bool[n + 1];

            for (int i = 2; i < isPrime.Length; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i < isPrime.Length; i++)
            {
                if (isPrime[i])
                {
                    for (int j = 2 * i; j < isPrime.Length; j += i)
                    {
                        isPrime[j] = false;
                    }
                }
            }

            var primes = Enumerable.Range(0, isPrime.Length).Where(i => isPrime[i]).ToArray();
            Console.WriteLine(Enumerable.Range(1, primes.Length - 1).Select(i => primes[i - 1] + primes[i] + 1).Count(p => p <= n && isPrime[p]) >= k ? "YES" : "NO");
        }
    }
}


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

namespace _17A
{
    class Program
    {
        public static void Main(string[] args)
        {

            List<int> primes = new List<int>();
            int[] temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = temp[0], k = temp[1];
            for(int i = 2; i <= n; i++)
            {
                if (IsPrime(i))
                    primes.Add(i);
            }
            int counter = 0;
            for(int i = 0; i < primes.Count - 1; i++)
            {
                int t = primes[i] + primes[i + 1] + 1;
                if (IsPrime(t) && t <= n)
                    counter++;
                if (t > n || counter >= k) break;
            }
            Console.WriteLine((counter >= k) ? "YES" : "NO");

        }

        static bool IsPrime(int num)
        {
            if(num==2)return true;
            if (num < 2 || num % 2 == 0) return false;
            int limit = Convert.ToInt32( Math.Sqrt(num));
            for(int i = 3; i <= limit; i += 2)
            {
                if (num % i == 0) return false;
            }
            return true;
        }
    }
}


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

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public int Second;

			public int Third;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First > y.First || (x.First == y.First && x.Second < y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<Pair> Edges;
		}

		public static List<List<Vertex>> Graph = new List<List<Vertex>>();

/*		public static bool Dfs(int x, int y, int prevx, int prevy)
		{
			Graph[x][y].Was = 1;
			var result = false;
			foreach (var t in Graph[x][y].Edges)
			{
				if (Graph[t.First][t.Second].Was == 0)
					result |= Dfs(t.First, t.Second, x, y);
				else if (t.First != prevx || t.Second != prevy)
					return true;
			}

			return result;
		}*/

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		private static void Main()
		{
			var s = ReadString();
			var ans = 0;
			var curO = s[0];
			var curCt = 1;
			var i = 1;
			while (i < s.Length)
			{
				if (s[i] != curO)
				{
					ans++;
					curO = s[i];
					curCt = 1;
				}
				else
				{
					if (curCt == 5)
					{
						ans++;
						curCt = 1;
					}
					else
					{
						curCt++;
					}
				}
				i++;
			}
			ans++;
			Console.WriteLine(ans);
			Console.ReadLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var cp = ReadToken();
        var n = 1;
        var c = 0;
        for (int i = 0; i < cp.Length - 1; i++)
        {
            if (cp[i] == cp[i + 1])
            {
                c++;
                if (c == 5)
                {
                    n++;
                    c = 0;
                }
            }
            else
            {
                n++;
                c = 0;
            }
        }
        Write(n);
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    private static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c != '-' && (c < '0' || c > '9'));
        int sign = 1;
        if (c == '-')
        {
            sign = -1;
            c = reader.Read();
        }
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res * sign;
            res *= 10;
            res += c - '0';
        }
    }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(GetMax(n, n));
        }

        private static long GetMax(int i, int j)
        {
            if (i == 1 || j == 1)
                return 1;
            return GetMax(i - 1, j) + GetMax(i, j - 1);
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
class Problem
{
    static void Main()
    {
        int n = Convert.ToInt32( Console.ReadLine() );
        Console.WriteLine( kq( n - 1) );
    }

    private static string kq(int p)
    {
        long str = 1;
        for(int i = p + 1 ; i <= 2 * p ; i++)
            str*= i;
        for(int i = 1 ; i <= p ; i++)
            str /= i;
        return str.ToString();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long a1 = inputs1[0];
			long a2 = inputs1[1];

			var min = Math.Min(a1, a2);
			var max = a1 + a2 - min;

			if (max == 1)
			{
				Console.WriteLine(0);
				return;
			}

			long count = 0;
			while (min > 0 && max > 0)
			{
				while (max > 2)
				{
					min++;
					max -= 2;
					count++;
				}

				var temp = Math.Min(min, max);
				max = min + max - temp;
				min = temp;

				if (max == 1 || max == 2)
				{
					count++;
					break;
				}
			}

			Console.WriteLine(count);
		}

		public class Team
		{
			public string Name { get; set; }

			public int Points { get; set; }

			public int GoalsFor { get; set; }

			public int GoalsAgainst { get; set; }
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            string [] input = Console.In.ReadLine().Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            input = null;
            int ans = (a + b - (Math.Abs(a - b) % 3 == 0 ? 3 : 2));
            Console.WriteLine(ans>0?ans:0);
        }
    }


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{
    #region MyIo

    class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        string[] tokens;
        int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }
    #endregion

    class Program
    {
        #region Program

        readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        void Solve()
        {
            var a = io.NextInt();
            var b = io.NextInt();

            for (int i = a + 1; i <= 200000 + b; i++)
            {
                if (CalcGood(i) == b)
                {
                    io.Print(i);
                    break;
                }
            }
        }

        private int CalcGood(int i)
        {
            int res = 0;
            int step = 1;

            while (i != 0)
            {
                int ost = i % 10;
                i /= 10;

                if (ost == 4 || ost == 7)
                {
                    res += ost * step;
                    step *= 10;
                }
            }

            return res;
        }

    }
}


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

namespace CodeForceContest
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ').Select(ss => int.Parse(ss)).ToArray();
            //var s = "401 4".Split(' ').Select(ss => int.Parse(ss)).ToArray();
            var a = s[0];
            var b = s[1];
            var res = a + 1;
            for (; ; )
            {
                if(TakeMask(res)==b)
                {
                    break;
                }
                res++;
            }
            Console.WriteLine(res);
        }
        static int TakeMask(int a)
        {
            var e = a.ToString();
            var list = new List<char>();
            foreach (var i in e)
            {
                if(i=='4' ||i=='7')list.Add(i);
            }
            if (list.Count > 0)
                return int.Parse(String.Join("", list.Select(s => s.ToString()).ToArray()));
            else return 0;
        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        string [] Input = Console.ReadLine().Split();
        int Parent = Int32.Parse(Input[0]);
        int Childs = Int32.Parse(Input[1]);
        int max, min;

        if (Childs == 0)
            max = Parent;
        else
            max = Parent + Childs - 1;
        if (Childs >= Parent) min = Parent + (Childs - Parent);
        else
            min = Parent;

        if (Parent == 0 && Childs != 0)
            Console.Write("Impossible");
        else
            Console.Write("{0} {1}", min, max);
    }
}


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

namespace Vasia
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, m;

            string s;
            string[] ss;

            s = Console.ReadLine();
            ss = s.Split();
            n = Convert.ToInt32(ss[0]);
            m = Convert.ToInt32(ss[1]);

            if (n == 0 & m == 0)
            {
                Console.WriteLine("{0} {1}", 0, 0);
                return;
            }

            if (n == 0)
            {
                Console.WriteLine("Impossible");
                return;
            }

            if(m == 0)
            {
                Console.WriteLine("{0} {1}", n, n);
                return;
            }

            if (n > m)
            {
                Console.WriteLine("{0} {1}", n, (n + m) - 1);
            }
            else
            {
                Console.WriteLine("{0} {1}", m, (n + m) - 1);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
            //using (var sr = new InputReader(new StreamReader("input.txt")))
            {
                var task = new Task();
                using (var sw = Console.Out)
                {
                    //using (var sw = new StreamWriter("output.txt")) {
                    task.Solve(sr, sw);
                    //Console.ReadKey();
                }
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = sr.ReadArrayOfInt32();
            if (n == 1) {
                sw.WriteLine("YES");
                return;
            }
            for (var i = 0; i < array.Length; i++) {
                for (var j = i; j < array.Length; j++) {
                    var can = true;
                    for (var k = 1; k <= i; k++) {
                        if (array[k] <= array[k - 1]) {
                            can = false;
                            break;
                        }
                    }
                    for (var k = i; k <= j; k++) {
                        if (array[k] != array[i]) {
                            can = false;
                            break;
                        }
                    }
                    for (var k = j + 1; k < array.Length; k++) {
                        if (array[k] >= array[k - 1]) {
                            can = false;
                            break;
                        }
                    }
                    if (can) {
                        sw.WriteLine("YES");
                        return;
                    }
                }
            }

            sw.WriteLine("NO");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Linq;

namespace Problem831A
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();

            Console.WriteLine(Check(a) ? "YES" : "NO");
        }

        static bool Check(int[] a)
        {
            int le = -1;
            int l = a.Length;
            int i = 0;
            if (l == 1)
                return true;

            while (i < l && a[i] > le)
            {
                le = a[i];
                i++;
            }
            if (i == l && a[l - 1] > a[l - 2])
                return true;

            if (a[i] == le)
            {
                while (i < l && a[i] == le)
                {
                    le = a[i];
                    i++;
                }

                if (i == l && a[l - 1] == a[l - 2])
                    return true;
            }
            le = a[i - 1];
            while (i < l && a[i] < le)
            {
                le = a[i];
                i++;
            }

            if (i != l)
                return false;

            return true;
        }
    }
}


using System;

namespace Skyscraper
{
    class Program
    {
        static void Main()
        {
            int t1 = Convert.ToInt32(Console.ReadLine());
            int t2 = Convert.ToInt32(Console.ReadLine());
            int t3 = Convert.ToInt32(Console.ReadLine());
            int t4 = Convert.ToInt32(Console.ReadLine());
            if (t3 > 0)
                if (t1 == 0)
                {
                    Console.WriteLine("0");
                    return;
        }
            if (t1 != t4)
            {
                Console.WriteLine("0");
                return;
            }
            Console.WriteLine("1");
        }
    }
}


/*
csc -debug A.cs && mono --debug A.exe <<< "3
1
4
3"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var A = cin.NextInt();
        var B = cin.NextInt();
        var C = cin.NextInt();
        var D = cin.NextInt();

        if (A + C + D == 0) {
            System.Console.WriteLine(1);
            return;
        }

        if (A == 0) {
            System.Console.WriteLine(0);
            return;
        }

        if (D != A) {
            System.Console.WriteLine(0);
            return;
        }

        System.Console.WriteLine(1);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ').ToList();
            long n = long.Parse(str[0]);
            long k = long.Parse(str[1]);
            int t = 0;
            int f = 0;

            long tmp = n;
            while(tmp % 2 == 0)
            {
                t++;
                tmp = tmp / 2;
            }
             tmp= n;
            while(tmp % 5 == 0)
            {
                f++;
                tmp /= 5;
            }

            if (k == 0) { Console.WriteLine(n); return; }

            long t1 = (k - t) > 0 ? k - t : 0;
            long f2 = (k - f) > 0 ? k - f : 0;

            long val = n * ((long) Math.Pow(2, t1)) * ((long) Math.Pow(5, f2));

            Console.WriteLine(val);

        }
    }


using System;

namespace CodeForces
{
	class A
	{
		static long gcd(long a, long b)
		{
			while (b != 0)
			{
				long temp = b;
				b = a % b;
				a = temp;
			}
			return a;
		}

		static long lcm(long m, long n)
		{
			return (m / gcd(m, n)) * n;
		}

		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string[] d = s.Split(' ');
			long n = long.Parse(d[0]);
			int k = int.Parse(d[1]);
			int div = (int) Math.Pow(10, k);

			Console.WriteLine(lcm(n, div));
		}
	}
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var x = ri;
        var y = ri;
        long res = 0;
        if (y < x)
        {
            var buf = y;
            y = x;
            x = buf;
        }
        for (int i = 1; i <= x; i++)
        {
            res += (y + (i % 5)) / 5;
        }
        wln(res);
    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }
    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeforcesRound358A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split();

            int n = Convert.ToInt32(inp[0]);
            int m = Convert.ToInt32(inp[1]);
            int k = 0;

            long cnt = 0;

            for (int i = 1; i <= n; i++)
            {
                k = (i/5 + 1) * 5 - i;

                cnt += m / 5;
                if (m % 5 >= k)
                    cnt++;
            }

            Console.WriteLine(cnt);
            //inp = Console.ReadLine().Split();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var n = ReadInt();
        var b = ReadIntArray().OrderBy(d => d).ToArray();
        var c = 0;
        for (int i = 0; i < n; i++)
        {
            if (i + 1 > c * (b[i] + 1))
            {
                c++;
            }
        }
        writer.WriteLine(c);
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    private static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c != '-' && (c < '0' || c > '9'));
        int sign = 1;
        if (c == '-')
        {
            sign = -1;
            c = reader.Read();
        }
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res * sign;
            res *= 10;
            res += c - '0';
        }
    }
    #endregion
}


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

public class Program
{
    public static void Main(string[] args)
    {
        var n = Int32.Parse(Console.ReadLine());
        var X = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
        Array.Sort(X);
        n++;
        var list = new int[n];
        foreach (var x in X)
        {
            var y = x;
            for (int i = 0; i < n; i++)
            {
                if (list[i] <= y)
                {
                    list[i]++;
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++)
            if (list[i] == 0)
            {
                Console.WriteLine(i);
                return;
            }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;

        if (M == 0)
        {
            WriteLine(1);
            return;
        }

        if (N % 2 == 0)
        {
            if (M <= N / 2)
            {
                WriteLine(M);
                return;
            }
            else
            {
                WriteLine(N - M);
            }
        }
        else
        {
            int X = N / 2;
            if (true)
            {
                if (M <= X)
                {
                    WriteLine(M);
                }
                else
                {
                    WriteLine(N - M);
                }

            }
        }
    }

}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split().Select(t => Convert.ToInt32(t)).ToArray();
            (int n, int m) = (nm[0], nm[1]);
            int res = 1;
            if (m > 0)
                res = n / m >= 2 ? m : n - m;
            Console.WriteLine(res);
        }
    }
}


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

namespace CrocCupB
{
    class Program
    {
        static void Main(string[] args)
        {
            //получим исходные данные
            var nkList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var a = nkList[0];
            var b = nkList[1];
            var m = nkList[2];
            var r0 = nkList[3];

            var randGenerator = new RandGenerator(a, b, m, r0);
            var randList = new Dictionary<int,int>();

            //поищем цикл...
            var curRandom = randGenerator.GetNext();
            var cycleIndex = -1;
            var n = 0;
            while (!randList.ContainsKey(curRandom))
            {
                randList.Add(curRandom, n);
                curRandom = randGenerator.GetNext();
                n++;
            }

            Console.WriteLine(randList.Count - randList[curRandom]);
        }
    }

    internal class RandGenerator
    {
        private readonly int _a;
        private readonly int _b;
        private readonly int _m;
        private int _ri;

        public RandGenerator(int a, int b, int m, int r0)
        {
            _a = a;
            _b = b;
            _m = m;
            _ri = r0;
        }

        public int GetNext()
        {
            return _ri = (((_a*_ri) + _b)%_m);
        }
    }
}


using System;
using System.Collections.Generic;

namespace T2
{
    class Program
    {
        static Int32 a;
        static Int32 b;
        static Int32 m;
        static Int32 r0;

        static Int32 gen(Int32 r)
        {
            return (a * r + b) % m;
        }

        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split();
            a = Int32.Parse(input[0]);
            b = Int32.Parse(input[1]);
            m = Int32.Parse(input[2]);
            r0 = Int32.Parse(input[3]);
            Dictionary<Int32, Int32> vals = new Dictionary<int, int>();

            Int32 r = r0;

            Int32 klav = 0;
            while (true)
            {
                klav++;
                r = gen(r);
                if (vals.ContainsKey(r))
                {
                    Console.Write(klav - vals[r]);
                    break;
                }
                else
                {
                    vals.Add(r, klav);
                }
            }
        }
    }
}


// ReSharper disable All

namespace Codeforces
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            List<int> l = new List<int>();
            var n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
                l.Add(int.Parse(Console.ReadLine()));

            Stack<int> s = new Stack<int>();
            s.Push(3);

            List<int> lista = new List<int>();
            lista.Add(1);
            lista.Add(2);
            var res = 0;
            for (int i = 0; i < n; i++)
            {

                if (l[i] == 1)
                {
                    if (s.Contains(1))
                    {
                        res++;
                        break;
                    }

                    var temp = (from a in lista where a != 1 select a).FirstOrDefault();
                    lista.Remove(temp);
                    var sta = s.Pop();
                    lista.Add(sta);
                    s.Push(temp);
                }
                else if (l[i] == 2)
                {
                    if (s.Contains(2)) { res++;
                        break;
                    }

                    var temp = (from a in lista where a != 2 select a).FirstOrDefault();
                    lista.Remove(temp);
                    var sta = s.Pop();
                    lista.Add(sta);
                    s.Push(temp);
                }
                else if (l[i] == 3)
                {

                    if (s.Contains(3))
                    {
                        res++;
                        break;
                    }

                    var temp = (from a in lista where a != 3 select a).FirstOrDefault();
                    lista.Remove(temp);
                    var sta = s.Pop();
                    lista.Add(sta);
                    s.Push(temp);
                }

            }

            if(res == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }

}


using System;

class Program
{
    static void Swap(ref int Right, ref int Left)
    {
        int temp = Right;
        Right = Left;
        Left = temp;
    }

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int k1 = 1;
        int k2 = 2;
        int k3 = 3;
        for (int i = 0; i < n; i++)
        {
            int a = int.Parse(Console.ReadLine());
            if (k3 == a)
            {
                Console.WriteLine("NO");
                return;
            }
            if (a == k1)
                Swap(ref k2, ref k3);
            if (a == k2)
                Swap(ref k1, ref k3);
        }
        Console.WriteLine("YES");
    }
}


using System;

namespace _780B
{
    class c
    {
        public ulong sumDigits(ulong n)
        {
            ulong sum = 0;
            while (n != 0)
            {
                sum = sum + n % 10;
                n = n / 10;
            }
            return sum;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            c c = new c();
            int i,j;
            ulong max1 = 0, max2 = 0, sum=0,temp3;
            ulong[] a = new ulong[19];
            string x, temp;
            x = Console.ReadLine();
            temp = x;

            for (i = 0; i < x.Length; i++)
            {

                a[i] = Convert.ToUInt64(temp);
                temp3=c.sumDigits(a[i]);
                if (temp3 > max2)
                {
                    max2 = temp3;
                    max1 = a[i];
                }
                else if (temp3 == max2)
                {
                    if (a[i] > max1)
                    {
                        max1 = a[i];
                    }
                }

                temp = x;
                if (x[i] == '9')
                {
                    temp=temp.Remove(i, 1).Insert(i, "8");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '8')
                {
                    temp=temp.Remove(i, 1).Insert(i, "7");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '7')
                {
                    temp=temp.Remove(i, 1).Insert(i, "6");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '6')
                {
                    temp=temp.Remove(i, 1).Insert(i, "5");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '5')
                {
                    temp=temp.Remove(i, 1).Insert(i, "4");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '4')
                {
                    temp=temp.Remove(i, 1).Insert(i, "3");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '3')
                {
                    temp=temp.Remove(i, 1).Insert(i, "2");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '2')
                {
                    temp=temp.Remove(i, 1).Insert(i, "1");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

                else if (x[i] == '1')
                {
                    temp=temp.Remove(i, 1).Insert(i, "0");
                    for (j = i+1; j<x.Length; j++)
                    {
                        temp=temp.Remove(j, 1).Insert(j, "9");
                    }
                }

            }

            Console.WriteLine(max1);
        }
    }
}


using System;

namespace baaaaabki
{
    class Program
    {
        static int sumNum(string x)
        {
            int sum = 0;
            for (int i = 0; i < x.Length; i++)
            {
                sum += int.Parse(x.Substring(i, 1));
            }
            return sum;
        }

        static long Tru(long t)
        {
            long x = t;
            string strH = "8";
            string strM = "";

            long q = 0;

            if (x > 9)
            {
                strM = x.ToString().Substring(1);
                for (int i = 0; i < strM.Length - 1; i++)
                {
                    strH += "9";
                }
                if (sumNum(strM) < 9 * strM.Length - 1)
                {
                    if (long.Parse(strM) < long.Parse(strH))
                    {
                        //Console.WriteLine(long.Parse((byte.Parse(x.ToString().Substring(0, 1)) - 1) + "9" + strH.Substring(1)));
                        q = long.Parse((byte.Parse(x.ToString().Substring(0, 1)) - 1) + "9" + strH.Substring(1));
                    }
                    else
                    {
                        int strHLen = strH.Length, k = 2;
                        strH = strH.Substring(1) + "8";
                        while (long.Parse(strH) > long.Parse(strM))
                        {
                            strH = "";
                            for (int i = 0; i < strHLen - k; i++)
                            {
                                strH += "9";
                            }
                            strH += "8";
                            for (int i = strHLen - k + 1; i < strHLen; i++)
                            {
                                strH += "9";
                            }
                            k++;
                        }
                        //Console.WriteLine(x.ToString().Substring(0, 1) + strH);
                        q = long.Parse(x.ToString().Substring(0, 1) + strH);
                    }
                }
                else
                {
                    //Console.WriteLine(x);
                    q = x;
                }
            }
            else
            {
                //Console.WriteLine(x);
                q = x;
            }
            return q;
        }
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            Console.WriteLine(Tru(x));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
#if  LOCAL_TEST
        private readonly TextReader inputStream = new StreamReader("input.txt");
#else
        private readonly TextReader inputStream = Console.In;
#endif
#if  FBHC_TEST
        private readonly TextWriter outputStream = new StreamWriter("output.txt");
#else
        private readonly TextWriter outputStream = Console.Out;
#endif

        private string[] tokens;
        private int pointer;

        public char NextChar()
        {
            try
            {
                var c = inputStream.Read();

                if (c < 0)
                    c = 0;

                return (char)c;
            }
            catch (IOException)
            {
                return '\0';
            }
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = (NextLine() + string.Empty).Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            var t = typeof(T);

            if (t == typeof(char))
                return (T)(object)NextChar();

            object s = NextString();

            if (t == typeof(string))
                return (T)s;

            return (T)Convert.ChangeType(s, typeof(T));
        }

        public IEnumerable<T> NextWhile<T>(Predicate<T> pred)
        {
            if (pred == null)
                yield break;

            var res = Next<T>();

            while (pred(res))
            {
                yield return res;

                res = Next<T>();
            }
        }

        public IEnumerable<T> NextSeq<T>(long n)
        {
            for (var i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            var ienum = o as IEnumerable;

            if (ienum != null && typeof(T) != typeof(string))
            {
                var first = true;

                foreach (var iev in ienum)
                {
                    if (!first && iev != null)
                        Print(" ");

                    Print(iev);

                    first = false;
                }

            }
            else
            {
                outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));
            }

        }

        public void PrintLine<T>(T o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static void Each<T>(this IEnumerable<T> self, Action<T> action)
        {
            foreach (var v in self)
                action(v);
        }

        public static string Reverse(this string s)
        {
            var charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<int, IList<T>, T> fval)
        {
            for (var i = 0; i < self.Count; i++)
                self[i] = fval(i, self);

            return self;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<int, T> fval)
        {
            return self.Fill((x, slf) => fval(x));
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<T> fval)
        {
            return self.Fill(x => fval());
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            return self.Fill(() => val);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long> val = null)
        {
            return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long, long> val)
        {
            return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));
        }

        public static long HashOne<T>(this T self, long current)
        {
            return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));
        }

        public static IList<T1> BuildSegTree<T1, T2>(this IList<T2> a, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            var t = new T1[a.Count << 2];

            a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);

            return t;
        }

        private static void BuildSegTree<T1, T2>(this IList<T2> a, IList<T1> t, int v, int tl, int tr, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            if (tl == tr)
            {
                t[v] = convert(a[tl]);
            }
            else
            {
                int tm = (tl + tr) >> 1;

                BuildSegTree(a, t, v << 1, tl, tm, combine, convert);
                BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);

                t[v] = combine(t[v << 1], t[(v << 1) + 1]);
            }
        }

        public static int Xor1n(this int n)
        {
            return (n >> 1) & 1 ^ ((n & 1) > 0 ? 1 : n);
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override bool Equals(object obj)
        {
            var co = obj as P<T1, T2>;

            return co != null && co.GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = unchecked(hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode()));
            hash = unchecked(hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode()));
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private void Solve()
        {
            var n = io.NextInt();
            var s = io.NextInt();

            var max = -1;
            var sum = 0;

            for (int i = 0; i < n; i++)
            {
                var ni = io.NextInt();

                sum += ni;

                if (ni > max)
                    max = ni;
            }

            io.PrintLine((sum - max > s) ? "NO" : "YES");
        }

    }

}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] ss = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(ss[0]);
            int  m= Convert.ToInt32(ss[1]);
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[n];

                for (int i = 0; i < n; i++)
                {
                    a[i] = Convert.ToInt32(s[i]);
                }
            Array.Sort(a);

                int b = 0;
                for (int i = 0; i < n -1; i++)
                {
                    b =b+ a[i];
                }

                if (b >m)
                    Console.WriteLine("NO");
                else
                    Console.WriteLine("YES");
            }

    }
}