using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using static Codeforces.IO;
using static System.Linq.Enumerable;

namespace Codeforces
{
    static class IO
    {
        static StringBuilder builder = new StringBuilder();
        static Dummy dummy = new Dummy();
        class Dummy
        {
            ~Dummy()
            {
                Console.Write(builder);
            }
        }
        public static void Write(object obj)
        {
            builder.Append(obj);
        }
        public static void WriteLine(object obj)
        {
            builder.AppendLine(obj.ToString());
        }
        public static void Write(params object[] objs)
        {
            if (objs.Length != 0)
            {
                Write(objs[0]);
                for (var i = 1; i < objs.Length; ++i)
                {
                    Write(" ");
                    Write(objs[i]);
                }
            }
        }
        public static void WriteLine(params object[] objs)
        {
            Write(objs);
            WriteLine();
        }

        public static void WriteLine()
        {
            builder.AppendLine();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }
        public static T ReadLine<T>(Func<string, T> parser)
        {
            return parser(ReadLine());
        }
        public static T[] ReadArray<T>(Func<string, T> parser)
        {
            return ReadLine().Split(' ').Select(parser).ToArray();
        }
        public static string[] ReadArray()
        {
            return ReadLine().Split(' ');
        }
        public static (T, T) ReadTuple2<T>(Func<string, T> parser)
        {
            var ar = ReadArray(parser);
            return (ar[0], ar[1]);
        }
        public static (string, string) ReadTuple2()
        {
            var ar = ReadArray();
            return (ar[0], ar[1]);
        }
        public static (T, T, T) ReadTuple3<T>(Func<string, T> parser)
        {
            var ar = ReadArray(parser);
            return (ar[0], ar[1], ar[2]);
        }
        public static (string, string, string) ReadTuple3()
        {
            var ar = ReadArray();
            return (ar[0], ar[1], ar[2]);
        }
    }

    static class Program
    {
        struct ModNum
        {
            public static long mod = 1000000007;

            long val;
            public ModNum(long v)
            {
                v %= mod;
                if (v < 0)
                {
                    v += mod;
                }
                this.val = v;
            }
            public static implicit operator ModNum(long v)
            {
                return new ModNum(v);
            }
            public static implicit operator ModNum(int v)
            {
                return new ModNum(v);
            }

            public static ModNum operator +(ModNum lhs, ModNum rhs)
            {
                return new ModNum(lhs.val + rhs.val);
            }
            public static ModNum operator -(ModNum lhs, ModNum rhs)
            {
                return new ModNum(lhs.val - rhs.val);
            }
            public static ModNum operator *(ModNum lhs, ModNum rhs)
            {
                return new ModNum(lhs.val * rhs.val);
            }
            public static ModNum operator /(ModNum lhs, ModNum rhs)
            {
                var right = new ModNum(1);
                long m = mod - 2;
                for (long i = 1; i <= mod - 2; i *= 2)
                {
                    if ((i & m) != 0)
                    {
                        right *= rhs;
                    }
                    rhs *= rhs;
                }
                return lhs * right;
            }

            public override string ToString()
            {
                return this.val.ToString();
            }
        }

        static void Main(string[] args)
        {
            var (N, M) = ReadTuple2(int.Parse);
            ModNum.mod = M;
            var fact = new ModNum[N + 1];
            fact[0] = 1;
            foreach(var i in Range(1, N))
            {
                fact[i] = fact[i - 1] * i;
            }
            var result = new ModNum();
            foreach(var i in Range(0, N))
            {
                result += fact[N - 1 - i] * fact[i + 1] * (N - i) * (N - i);
            }
            WriteLine(result);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = System.Console.ReadLine().Split(' ');

            int a1 = int.Parse(s[0]);
            int a2 = int.Parse(s[1]);

            int p = a2 - a1;

            for (int i = 2; i < s.Count(); i++)
            {
                int t = int.Parse(s[i]);
                if (a2 + p != t)
                {
                    System.Console.Write(0);
                    return;
                }
                a2 = t;
            }

            System.Console.Write(1);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = System.Console.ReadLine().Split(' ');

            int[] mas = new int[5];

            for (int i = 0; i < 5; i++)
            {
                mas[i] = int.Parse(s[i]);
            }

            mas[2] /= 2;
            mas[3] /= 7;
            mas[4] /= 4;

            int min = int.MaxValue;
            for (int i = 0; i < 5; i++)
            {
                if (min > mas[i])
                {
                    min = mas[i];
                }
            }
            System.Console.Write(min);
        }
    }
}


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

namespace codeforces
{
    class Program
    {
        //16:23
        //reading
        static string ReadLine()
        {
            return Console.ReadLine();
        }
        static string[] ReadArray()
        {
            return ReadLine().Split(' ');
        }
        static List<string> ReadList()
        {
            return ReadArray().ToList();
        }
        static List<int> ReadIntList()
        {
            return ReadArray().Select(c => Convert.ToInt32(c)).ToList();
        }
        static List<long> ReadLongList()
        {
            return ReadArray().Select(c => Convert.ToInt64(c)).ToList();
        }
        static List<ulong> ReadULongList()
        {
            return ReadArray().Select(c => Convert.ToUInt64(c)).ToList();
        }
        static int ToInt(string str)
        {
            return Convert.ToInt32(str);
        }
        static long ToInt64(string str)
        {
            return Convert.ToInt64(str);
        }
        static ulong ToUInt64(string str)
        {
            return Convert.ToUInt64(str);
        }

        static void Main(string[] args)
        {
            List<int> lst = ReadIntList();

            int count = int.MaxValue;
            count = Math.Min(lst[0], count);
            count = Math.Min(lst[1], count);
            count = Math.Min(lst[2] / 2, count);
            count = Math.Min(lst[3] / 7, count);
            count = Math.Min(lst[4] / 4, count);
            Console.WriteLine(count);

            /*
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine(elapsedMs);*/
        }
    }
}


using System;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ');
            var n = Int32.Parse(arr[0]);
            var m = long.Parse(arr[1]);
            var res = GetRes(n, m);
            Console.WriteLine(res);

            // Test();
        }

        const int MOD_VAL = 998244353;
        private static int GetRes(int n, long m)
        {
            if (n == 1) return 0;
            var fullCount = GetFullCount(n, m);
            var noOk = GetNOKCount(n,m);
            var res = fullCount - noOk;
            if(res < 0) res+=MOD_VAL;
            return res;
        }

        private static int GetFullCount(int n, long m)
        {
            var divisor = (int)((m-1) % MOD_VAL);
            if (divisor == 0) return n;
            var reverse = GetReverse(divisor);
            var mAfterMod = (int)(m % MOD_VAL);
            var res = (int)(((long)GetPow(mAfterMod, n+1) - mAfterMod) *
                reverse % MOD_VAL);
            if (res < 0) res+=MOD_VAL;
            return res;
        }

        private static int GetReverse(int val)
        {
            var (a,b) = ExGcd(MOD_VAL, val);
            return b >= 0 ? (int) b: (int)(MOD_VAL+b);
        }

        private static (long, long) ExGcd(long num0, long num1)
        {
            if (num0 % num1 == 0)
            {
                return (0, 1);
            }
            // a0 * num0 + b0 * num1 = num2
            var num2 = num0 % num1;
            var a0 = 1;
            var b0 = -(num0 / num1);
            // a1 * num1 + b1 * num2 = gcd
            var (a1, b1) = ExGcd(num1, num2);
            // (a0*b1) * num0 + (a1 + b0*b1) * num1 = gcd
            return (a0 * b1, a1 + b0 * b1);
        }

        private static int GetPow(int baseVal, int exponent)
        {
            var index = 0;
            var res = 1L;
            long tmp = baseVal;
            while(1<<index <= exponent)
            {
                if ((1<<index & exponent)!=0)
                {
                    res = res * tmp % MOD_VAL;
                }
                tmp = tmp * tmp % MOD_VAL;
                index++;
            }
            return (int)res;
        }

        private static int GetNOKCount(int n, long m)
        {
            var primes = new int[]
            {
                2,3,5,7,11,13,17,19,23,29,31,37
            };
            var product = 1L;
            var noOkI = m % MOD_VAL;
            var noOk = noOkI;
            for(var i =2;i<=n;i++)
            {
                if(primes.Contains(i))
                {
                    product*=i;
                }
                if( m < product)
                {
                    break;
                }
                noOkI = noOkI * (m/product % MOD_VAL) % MOD_VAL;
                noOk = (noOk + noOkI) % MOD_VAL;
            }
            return (int)noOk;
        }

        private static (int,int) GetTestData(Random random)
        {
            return (random.Next(10)+3, random.Next(4));
        }

    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            int n = ReadInt();
            string[] a = new string[n];
            string[] b = new string[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLine();
            }
            for (int i = 0; i < n; i++)
            {
                b[i] = ReadLine();
            }

            Func<Point, Point> rotate = point => new Point(point.Y, n - 1 - point.X);
            Func<Point, Point> flip = point => new Point(n - 1 - point.X, point.Y);

            if (Check(n, a, b, point => point) ||
                Check(n, a, b, point => rotate(point)) ||
                Check(n, a, b, point => rotate(rotate(point))) ||
                Check(n, a, b, point => rotate(rotate(rotate(point)))) ||
                Check(n, a, b, point => flip(point)) ||
                Check(n, a, b, point => flip(rotate(point))) ||
                Check(n, a, b, point => flip(rotate(rotate(point)))) ||
                Check(n, a, b, point => flip(rotate(rotate(rotate(point))))))
            {
                Writer.WriteLine("Yes");
            }
            else
            {
                Writer.WriteLine("No");
            }
        }

        public static bool Check(int n, string[] a, string[] b, Func<Point, Point> transformation)
        {
            for (int x = 0; x < n; x++)
            {
                for (int y = 0; y < n; y++)
                {
                    var p = transformation(new Point(x, y));
                    if (a[x][y] != b[p.X][p.Y])
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            /*sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public class Point
        {
            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }

            public int X;

            public int Y;

            public double Length => Math.Sqrt(X * X + Y * Y);

            protected bool Equals(Point other)
            {
                return X == other.X && Y == other.Y;
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj))
                {
                    return false;
                }
                if (ReferenceEquals(this, obj))
                {
                    return true;
                }
                /*if (obj.GetType() != this.GetType())
                {
                    return false;
                }*/
                return Equals((Point) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (X * 397) ^ Y;
                }
            }

            public int Dist2(Point p)
            {
                return (p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y);
            }

            public static Point operator +(Point a, Point b)
            {
                return new Point(a.X + b.X, a.Y + b.Y);
            }

            public static Point operator -(Point a, Point b)
            {
                return new Point(a.X - b.X, a.Y - b.Y);
            }

            public override string ToString()
            {
                return $"{nameof(X)}: {X}, {nameof(Y)}: {Y}";
            }
        }

        public static void Main()
        {
            //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            Solve();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        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 string ReadLine()
        {
            return Reader.ReadLine();
        }

        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 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));
        }

        #endregion
    }
}


/* Date: 14.04.2018 * Time: 21:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

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

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2018\\Task\\07 Codeforces\\030\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2018\\Task\\07 Codeforces\\030\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
# else
		n = int.Parse (sr.ReadLine ());
		sw.WriteLine ("n = " + n);
# endif

		string [] mapA = new string [n];

		for ( int i=0; i < n; i++ )
		{
# if ( ONLINE_JUDGE )
			mapA [i] = Console.ReadLine ();
# else
			mapA [i] = sr.ReadLine ();
# endif
		}

		string [] mapB = new string [n];

		for ( int i=0; i < n; i++ )
		{
# if ( ONLINE_JUDGE )
			mapB [i] = Console.ReadLine ();
# else
			mapB [i] = sr.ReadLine ();
# endif
		}

# if ( ! ONLINE_JUDGE )
		for ( int i=0; i < n; i++ )
			sw.WriteLine (mapA [i]);
		sw.WriteLine ();
		for ( int i=0; i < n; i++ )
			sw.WriteLine (mapB [i]);
		sw.WriteLine ();
# endif

		//
		bool ok0 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [i][j] )
				{
					ok0 = false; break;
				}
			if ( ! ok0 )
				break;
		}
		//
		bool ok1 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [i][n-j-1] )
				{
					ok1 = false; break;
				}
			if ( ! ok1 )
				break;
		}
		//
		bool ok2 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [n-1-i][j] )
				{
					ok2 = false; break;
				}
			if ( ! ok2 )
				break;
		}
		//
		bool ok3 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [n-1-i][n-1-j] )
				{
					ok3 = false; break;
				}
			if ( ! ok3 )
				break;
		}
		//
		bool ok4 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [i][j] != mapB [j][n-1-i] )
				{
					ok4 = false; break;
				}
			if ( ! ok4 )
				break;
		}
		//
		bool ok5 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [j][n-1-i] != mapB [i][j] )
				{
					ok5 = false; break;
				}
			if ( ! ok5 )
				break;
		}
		//
		bool ok6 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [j][i] != mapB [i][j] )
				{
					ok6 = false; break;
				}
			if ( ! ok6 )
				break;
		}
		//
		bool ok7 = true;
		for ( int i=0; i < n; i++ )
		{
			for ( int j=0; j < n; j++ )
				if ( mapA [n-1-j][n-1-i] != mapB [i][j] )
				{
					ok7 = false; break;
				}
			if ( ! ok7 )
				break;
		}
		//
		bool ok = ok0 || ok1 || ok2 || ok3 || ok4 || ok5 || ok6 || ok7;
		//
# if ( ONLINE_JUDGE )
		if ( ok )
			Console.WriteLine ("Yes");
		else
			Console.WriteLine ("No");
# else
		if ( ok )
			sw.WriteLine ("Yes");
		else
			sw.WriteLine ("No");
		sw.Close ();
# endif

	}

}


using System;

namespace _1505B._DMCA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n > 9)
            {
                Console.WriteLine(9);
            }
            else
            {
                Console.WriteLine(n);
            }
            //baaler problem part 2
        }
    }
}


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

namespace cs_console
{
    class _73_2_E
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] b = new int[n + 1];
            b[1] = -1;
            for (int i = 2; i <= n; i++)
            {
                b[i] = -1;
                for (int len = 2; len * (len + 1) / 2 <= i; len++)
                {
                    if (i * 2 % len == 0)
                    {
                        int aa = i * 2 / len - len + 1;
                        if (aa % 2 == 0 && aa > 0)
                        {
                            int x = aa / 2;
                            //(x, len)
                            bool ok = true;
                            for (int k = 0; k < len; k++)
                            {
                                if (b[x + k] >= 0)
                                {
                                    ok = !ok;
                                }
                            }
                            if (ok)
                            {
                                b[i] = len;
                                break;
                            }
                        }
                    }
                }
            }
            //for (int i = 0; i < n; i++)
            //{
            //    Console.WriteLine(i + " " + b[i]);
            //}
            Console.WriteLine(b[n]);
        }
    }
}


using System;

namespace Codeforces
{
    class Program
    {
        static void Main()
        {
            var N = Int32.Parse(Console.ReadLine().Trim());

            int[] grandi = new int[N+1];
            int[] numGrandi = new int[N+1];
            int nim;
            int[] answ = new int[N+1];

            for (int i = 0; i < N + 1; i++)
            {
                numGrandi[i] = -1;
                answ[i] = -1;
            }
            for (int n = 0; n <= N; n++)
            {
                for (int count = 2; (count * (count + 1)) / 2 <= n; count++)
                {
                    if ((2 * n - count * (count - 1)) % (2 * count) != 0)
                        continue;
                    int a = (2 * n - count * (count - 1)) / (2 * count);
                    if (a < 1)
                        break;

                    nim = 0;
                    for (int j = 0; j < count; j++)
                        nim ^= grandi[a + j];

                    if (answ[n] == -1)
                    {
                        if (nim == 0)
                            answ[n] = count;
                        else
                            answ[n] = -1;
                    }
                    numGrandi[nim] = n;
                }
                for (int i = 0; i <= N; i++)
                {
                    if (numGrandi[i] != n)
                    {
                        grandi[n] = i;
                        break;
                    }
                }
            }

            Console.WriteLine(answ[N]);
        }
    }
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n = int.Parse(Console.ReadLine());
            Int64 d = 1000000007;
            Int64 res = (2*n*n+n) % d;
            res = n % d;
            res *= 2;
            res *= n % d;
            res += n % d;
            res %= d;
            Console.WriteLine(res);
        }
    }
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n = Int64.Parse(Console.ReadLine());
            Int64 d = 1000000007;
            Int64 p = (Int64)Math.Pow(2, n);
            Int64 res = (p * p + p) / 2;
            res %= d;
            Console.WriteLine(res);
        }
    }
}


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

namespace CodeForces {
    class Pair : IComparable<Pair> {
        public int First, Second,Index;
        public Pair(int f, int s) {
            First = f;
            Second = s;
        }
        public Pair(string s) {
            string[] ss = s.Split(' ');
            First = int.Parse(ss[0]);
            Second = int.Parse(ss[1]);
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return Math.Abs(other.Second).CompareTo(Math.Abs(Second));
        }
    }

    class Cf {
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            Stopwatch sw = new Stopwatch();
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.WriteLine();
            Console.WriteLine("Milliseconds: {0}", sw.ElapsedMilliseconds);
            Console.ReadLine();
#endif
        }
        const int MOD = 1000000007;
        static int n, m;
        static string s, t;
        static void Solve() {
            ulong n = ulong.Parse(input.ReadLine());
            if (n == 0)
                Console.WriteLine(1);
            else {
                ulong p1 = binpow(2, n - 1);
                ulong p2 = binpow(2, 2 * n - 1);
                ulong res = (p1 + p2) % MOD;
                Console.WriteLine(res);
            }
        }

        static ulong binpow(ulong a, ulong n) {
            ulong res = 1;
            while (n > 0)
                if ((n & 1)==1) {
                    res = (res * a) % MOD;
                    --n;
                }
                else {
                    a = (a * a) % MOD;
                    n >>= 1;
                }
            return res % MOD;
        }

        static void PrintDouble(double d) {
            Console.WriteLine(d.ToString().Replace(',','.'));
        }

        static int[] Z_function(string s) {
            int n = s.Length;
            int[] z = new int[n];
            for (int i = 1, l = 0, r = 0; i < n; ++i) {
                if (i <= r)
                    z[i] = Math.Min(r - i + 1, z[i - l]);
                while (i + z[i] < n && s[z[i]] == s[i + z[i]])
                    ++z[i];
                if (i + z[i] - 1 > r) {
                    l = i; r = i + z[i] - 1;
                }
            }
            return z;
        }

        static int SquaredDistanceBetweenSegments(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) {
            return Math.Min(Math.Min(SquaredDistanceToSegment(x1, y1, xx1, yy1, xx2, yy2), SquaredDistanceToSegment(x2, y2, xx1, yy1, xx2, yy2)),
                Math.Min(SquaredDistanceToSegment(xx1, yy1, x1, y1, x2, y2), SquaredDistanceToSegment(xx2, yy2, x1, y1, x2, y2)));
        }

        static int SquaredDistanceToSegment(int x, int y, int x1, int y1, int x2, int y2) {
            int result = Math.Min(SquaredDistance(x, y, x1, y1), SquaredDistance(x, y, x2, y2));
            if (x1 == x2 && y1 <= y && y <= y2)
                result = (x - x1) * (x - x1);
            else if (y1 == y2 && x1 <= x && x <= x2)
                result = (y - y1) * (y - y1);
            return result;
        }

        static int SquaredDistance(int ax, int ay, int bx, int by) {
            return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
        }

        #region read helpers
        public static List<int> ReadIntList() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
#endregion
    }

    public class SegmentTree {
        private int[] a, t;
        private int n;
        public SegmentTree(int[] a) {
            n = a.Length;
            this.a = a;
            t = new int[n << 2];
            buildSegmentTree(0, n - 1, 1);
        }

        private void buildSegmentTree(int l, int r, int v) {
            if (l == r)
                t[v] = a[l];
            else {
                int m = (l + r) >> 1;
                int vl = v << 1;
                int vr = (v << 1) | 1;
                buildSegmentTree(l, m, vl);
                buildSegmentTree(m + 1, r, vr);
                t[v] = t[vl] + t[vr];
            }
        }

        public int QuerySegmentTree(int l, int r) {
            return querySegmentTree(1, l, r, 0, n - 1);
        }

        public void Update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    Update(v << 1, tl, tm, pos, new_val);
                else
                    Update(v << 1 + 1, tm + 1, tr, pos, new_val);
                t[v] = t[v << 1] + t[v << 1 + 1];
            }
        }

        private int querySegmentTree(int v, int l, int r, int tl, int tr) {
            if (l > r)
                return 0;
            if (l == tl && r == tr)
                return t[v];
            int m = (tl + tr) >> 1;
            return querySegmentTree(v << 1, l, Math.Min(r, m), tl, m) + querySegmentTree((v << 1) | 1, Math.Max(l, m + 1), r, m + 1, tr);
        }
    }
    class Graph : List<List<int>> {
        public Graph(int num): base(num) {
            for (int i = 0; i < num; i++) {
                this.Add(new List<int>());
            }
        }
    }
    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }
    public static class Extensions {
        public static void Fill(this int[] array, int val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static void Fill(this double[] array, double val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static int ToInt(this string s) {
            return int.Parse(s);
        }

        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static void Print<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}


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

namespace MakeCalendar
{
    class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

//----------------------------------------------------------------------------

        static decimal findrem(decimal n, int p)
        {
            if (n == 0)
                return 1;
            if (n % 2 == 0)
                return (findrem(n / 2, p) * findrem(n / 2, p)) % p;
            n--;
            return (findrem(n / 2, p) * findrem(n / 2, p)*2) % p;
        }

        static void Main(string[] args)
        {
            decimal n = Convert.ToDecimal(Console.ReadLine());

            if (n == 0)
            { PrintLn(1); return; }

            int p = 1000000007;

            PrintLn((findrem(n-1,p)*(findrem(n,p)+1))%p);

        }

    }
}


using System;
using System.Linq;

namespace GoldPigeon
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            string[] line = Console.ReadLine().Split(' ');

            for(int i = 0; i < n; i++)
            {
                a[i] = int.Parse(line[i]);
            }

            Console.WriteLine(a[a.Min() + 2]);
            Console.ReadKey();
        }
    }
}


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

namespace GoldPigeon
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            string[] line = Console.ReadLine().Split(' ');

            for(int i = 0; i < n; i++)
            {
                a[i] = int.Parse(line[i]);
            }

            Console.WriteLine(a[a.Min() + 2]);
            Console.ReadKey();
        }
    }
}


using System;

namespace GoldPigeon
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = new int[n];
            string[] line = Console.ReadLine().Split(' ');
            int min = int.MaxValue;

            for(int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt32(line[i]);
                min = min > a[i] ? a[i] : min;
            }

            Console.WriteLine(a[min + 2]);
        }
    }
}


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

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            int num2 = 0;
            int n = int.Parse(Console.ReadLine());
            int[][] toks = new int[3][];

            for(int i = 0; i < n; i++)
            {
                int[] temp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                toks[i] = temp;
            }

            int number = 0;
            for(int x = 0; x <= 100; x++)
            {
                number++;
                string tofind = number.ToString();
                int num1 = int.Parse(tofind[0].ToString());
                if (tofind.Length == 2)
                {
                    num2 = int.Parse(tofind[1].ToString());
                }
                bool naid = false;
                for(int i = 0; i < n; i++)
                {
                    if(toks[i].Contains(num1))
                    {
                        naid = true;
                        if(tofind.Length == 1)
                        {
                            break;
                        }
                        else
                        {
                            naid = false;
                            for(int j = 0; j < n; j++)
                            {
                                if (j == i)
                                    continue;
                                if(toks[j].Contains(num2))
                                {
                                    naid = true;
                                    i = n;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (naid == false)
                    break;

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


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            int noOfCubes = -1;
            List<int[]> cubes = new List<int[]>();
            int[] digits = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int.TryParse(Console.ReadLine(), out noOfCubes);
            for (int i = 0; i < noOfCubes; i++)
            {
                var a = Console.ReadLine().Split(' ');
                int[] cube = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                foreach (var d in a)
                {
                    var j = 0;
                    int.TryParse(d, out j);
                    cube[j] = 1;
                    digits[j]++;
                }
                cubes.Add(cube);
            }

            for (int i = 1; i <= noOfCubes; i++)
            {
                for (int j = 0; j < digits.Length; j++)
                {
                    if (j == 0 && digits[j] < (i - 1))
                    {
                        var abc = Math.Pow(10, i - 1) - 1;
                        Console.WriteLine(abc);
                        return;
                    }
                    else if (j != 0 && digits[j] < i)
                    {
                        string result = "";
                        var oCubes = cubes.FindAll(c => c[j] == 0);
                        int[] abc = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        foreach (var c in oCubes)
                        {
                            for (int z = 0; z < 10; z++)
                            {
                                abc[z] += c[z];
                            }
                        }
                        for (int m = 0; m < 10; m++)
                        {
                            if (abc[m] == 0)
                            {
                                for (int n = 0; n < i - 1; n++)
                                {
                                    result += j.ToString();
                                }
                                if (m != 0)
                                {
                                    result += (m - 1).ToString();
                                    Console.WriteLine(int.Parse(result));
                                    return;
                                }
                                else if (m == 0 && i > 1)
                                {
                                    result += "0";
                                    Console.WriteLine(int.Parse(result) - 1);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(x);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e, ref int f)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4]; f = x[5];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        /*public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }*/

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ", col));
        }

        public static void PrintLn(params object[] v)
        {
            PrintLnCollection(v);
        }

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

        public static string MySubstring(this string str, int start, int finish)
        {
            if (start > finish) return "";
            return str.Substring(start, finish - start + 1);
        }

        public static string Reverse(this string str)
        {
            if (str == null) return null;

            return new string(str.ToArray().Reverse().ToArray());
        }
        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a >= lb) && (a <= ub);
        }

        private static void mergeDS(int i, int j, int[] a)
        {
            int t = a[j];
            for (int ii = 0; ii < a.Length; ii++)
            {
                if (a[ii] == t)
                    a[ii] = a[i];
            }
        }

        private static T MyMax<T>(params T[] a)
        {
            return a.Max();
        }

        private static T MyMin<T>(params T[] a)
        {
            return a.Min();
        }

        private static int[] GetPrimesLessThan(int x)
        {
            if (x < 2)
                return new int[0];

            int[] a = new int[x];

            a[0] = 1; a[1] = 1;

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    for (int j = 2 * i; j < a.Length; j += i)
                    {
                        a[j] = 1;
                    }
            }

            var abc = new List<int>(x);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    abc.Add(i);
            }

            return abc.ToArray();
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target == a[mid])
                return mid;
            else if (target < a[mid])
                return FindNearestLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindNearestLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int target)
        {
            return FindNearestLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target < a[mid])
                return FindRightMostLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindRightMostLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int target)
        {
            return FindRightMostLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int gcd(int a, int b)
        {
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        //----------------------------------------------------------------------------

        static string GetSha1(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            using (BufferedStream bs = new BufferedStream(fs))
            {
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] hash = sha1.ComputeHash(bs);
                    StringBuilder formatted = new StringBuilder(2 * hash.Length);
                    foreach (byte b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }

                    return formatted.ToString();
                }
            }
        }

        static bool canFit(int a1, int b1, int a2, int b2)
        {
            int[] r1 = { a1, b1 };
            int[] r2 = { a2, b2 };

            Array.Sort(r1);
            Array.Sort(r2);

            bool ans = (r1[0] <= r2[0]) && (r1[1] <= r2[1]);

            return ans;

        }

        class Pair
        {
            public int first { get; set; }
            public int second { get; set; }
        }

        static bool IsPossible(string n, string[] cubes)
        {

            if (n.Length > cubes.Length)
                return false;

            if (n == "")
                return true;

            for (int i = 0; i < cubes.Length; i++)
            {
                if (cubes[i].Contains(n[0]))
                {
                    var temp = cubes[0];
                    cubes[0] = cubes[i];
                    cubes[i] = temp;

                    if (IsPossible(n.Substring(1), cubes.Skip(1).ToArray()))
                        return true;

                }
            }

            return false;
        }

        static void Main(string[] args)
        {

            int n = ReadIntLine();

            string[] cubes = new string[n];

            for (int i = 0; i < n; i++)
            {
                cubes[i] = string.Join("", ReadIntArrayLine());
            }

            int k = 0;

            while (IsPossible((k + 1).ToString(), cubes))
                k++;

            PrintLn(k);

        }

    }

}


using System;

namespace _887B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0;
            n = int.Parse(Console.ReadLine());
            int[,] array = new int[n, 6];
            for (int i = 0; i < n; i++)
            {
                //Console.Clear();
                string inputDice = Console.ReadLine();
                string[] splitInputDice =  inputDice.Split(' ');

                for (int j = 0; j < 6; j++)
                {
                    array[i, j] = int.Parse(splitInputDice[j]);
                }
            }

            int[] checker = new int[1000];
            Array.Clear(checker, 0, checker.Length);

            for (int i = 0; i < n; i++)
            {
                for(int j = 0; j < 6; j++)
                {
                    checker[array[i, j]] = 1;

                    for(int k = 0; k < n; k++ )
                    {
                        if (k == i) continue;
                        for(int l = 0; l < 6; l++)
                        {
                            int index = array[i, j] * 10 + array[k, l];
                            checker[index] = 1;
                            for(int m = 0; m < n; m++)
                            {
                                if (m == i || m == k) continue;
                                for(int o = 0; o < 6; o++)
                                {
                                    int index2 = array[i, j] * 100 + array[k, l] * 10 + array[m, o];
                                    checker[index2] = 1;
                                }
                            }
                        }
                    }
                }
            }

            int res = 0;
            for(int i = 1; i < 1000; i++)
            {
                if(checker[i] == 0)
                {
                    res = i - 1;
                    break;
                }
            }

            Console.Write(res);

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e, ref int f)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4]; f = x[5];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        /*public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }*/

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ", col));
        }

        public static void PrintLn(params object[] v)
        {
            PrintLnCollection(v);
        }

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

        public static string MySubstring(this string str, int start, int finish)
        {
            if (start > finish) return "";
            return str.Substring(start, finish - start + 1);
        }

        public static string Reverse(this string str)
        {
            if (str == null) return null;

            return new string(str.ToArray().Reverse().ToArray());
        }
        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a >= lb) && (a <= ub);
        }

        private static void mergeDS(int i, int j, int[] a)
        {
            int t = a[j];
            for (int ii = 0; ii < a.Length; ii++)
            {
                if (a[ii] == t)
                    a[ii] = a[i];
            }
        }

        private static T MyMax<T>(params T[] a)
        {
            return a.Max();
        }

        private static T MyMin<T>(params T[] a)
        {
            return a.Min();
        }

        private static int[] GetPrimesLessThan(int x)
        {
            if (x < 2)
                return new int[0];

            int[] a = new int[x];

            a[0] = 1; a[1] = 1;

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    for (int j = 2 * i; j < a.Length; j += i)
                    {
                        a[j] = 1;
                    }
            }

            var abc = new List<int>(x);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    abc.Add(i);
            }

            return abc.ToArray();
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target == a[mid])
                return mid;
            else if (target < a[mid])
                return FindNearestLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindNearestLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int target)
        {
            return FindNearestLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target < a[mid])
                return FindRightMostLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindRightMostLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindRightMostLEQElementInTheArray(int[] a, int target)
        {
            return FindRightMostLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int gcd(int a, int b)
        {
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        //----------------------------------------------------------------------------

        static string GetSha1(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            using (BufferedStream bs = new BufferedStream(fs))
            {
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] hash = sha1.ComputeHash(bs);
                    StringBuilder formatted = new StringBuilder(2 * hash.Length);
                    foreach (byte b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }

                    return formatted.ToString();
                }
            }
        }

        static bool canFit(int a1, int b1, int a2, int b2)
        {
            int[] r1 = { a1, b1 };
            int[] r2 = { a2, b2 };

            Array.Sort(r1);
            Array.Sort(r2);

            bool ans = (r1[0] <= r2[0]) && (r1[1] <= r2[1]);

            return ans;

        }

        class Pair
        {
            public int first { get; set; }
            public int second { get; set; }
        }

        static bool IsPossible(string n, string[] cubes)
        {

            if (n.Length > cubes.Length)
                return false;

            if (n == "")
                return true;

            for (int i = 0; i < cubes.Length; i++)
            {
                if (cubes[i].Contains(n[0]))
                {
                    var temp = cubes[0];
                    cubes[0] = cubes[i];
                    cubes[i] = temp;

                    if (IsPossible(n.Substring(1), cubes.Skip(1).ToArray()))
                        return true;
                    else
                    {
                        cubes[i] = cubes[0];
                        cubes[0] = temp;
                    }
                }
            }

            return false;
        }

        static void Main(string[] args)
        {

            int n = ReadIntLine();

            string[] cubes = new string[n];

            for (int i = 0; i < n; i++)
            {
                cubes[i] = string.Join("", ReadIntArrayLine());
            }

            int k = 0;

            while (IsPossible((k + 1).ToString(), cubes))
                k++;

            PrintLn(k);

        }

    }

}


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

namespace CF
{
    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")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private const int m = 6;
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;
        private int n;
        private int[,] cubs;
        HashSet<int> set = new HashSet<int>();

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

        public void Solve()
        {
            n = sr.NextInt32();
            cubs = new int[n, m];
            for (var i = 0; i < n; i++) {
                var input = sr.ReadArrayOfInt32();
                for (var j = 0; j < m; j++) {
                    cubs[i, j] = input[j];
                }
            }
            if (n == 1) {
                for (var i = 0; i < m; i++) {
                    set.Add(GetNumber(cubs[0, i]));
                }
            }
            if (n == 2) {
                for (var i = 0; i < m; i++) {
                    for (var j = 0; j < m; j++) {
                        set.Add(GetNumber(cubs[0, i]));
                        set.Add(GetNumber(cubs[0, i], cubs[1, j]));
                        set.Add(GetNumber( cubs[1, j], cubs[0, i]));
                        set.Add(GetNumber(cubs[1, j]));
                    }
                }
            }
            if (n == 3) {
                for (var i = 0; i < m; i++) {
                    for (var j = 0; j < m; j++) {
                        for (var k = 0; k < m; k++) {
                            set.Add(GetNumber(cubs[0, i]));
                            set.Add(GetNumber(cubs[1, j]));
                            set.Add(GetNumber(cubs[2, k]));
                            set.Add(GetNumber(cubs[0, i], cubs[1, j], cubs[2, k]));
                            set.Add(GetNumber(cubs[0, i], cubs[2, k], cubs[1, j]));

                            set.Add(GetNumber(cubs[1, j], cubs[0, i], cubs[2, k]));
                            set.Add(GetNumber(cubs[1, j], cubs[2, k], cubs[0, i]));

                            set.Add(GetNumber(cubs[2, k], cubs[0, i], cubs[1, j]));
                            set.Add(GetNumber(cubs[2, k], cubs[1, j], cubs[0, i]));

                            set.Add(GetNumber(cubs[0, i], cubs[1, j]));
                            set.Add(GetNumber(cubs[1, j], cubs[0, i]));

                            set.Add(GetNumber(cubs[1, j], cubs[2, k]));
                            set.Add(GetNumber(cubs[2, k], cubs[1, j]));

                            set.Add(GetNumber(cubs[0, i], cubs[2, k]));
                            set.Add(GetNumber(cubs[2, k], cubs[0, i]));
                        }
                    }
                }
            }
            foreach (var num in Enumerable.Range(1, 9 * 9 * 3)) {
                if (!set.Contains(num)) {
                    sw.WriteLine(num - 1);
                    return;
                }
            }
        }

        private int GetNumber(params int[] array)
        {
            var str = "";
            for (var i = 0; i < array.Length; i++) {
                str += array[i];
            }
            if (str[0] == '0' && array.Length > 1) {
                return 0;
            }

            return Int32.Parse(str);
        }

        ~Task()
        {
            Dispose(false);
        }

        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.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int n;
    bool[,] a;
    bool Fun(string s, int p, bool[] used)
    {
        if (p == s.Length)
            return true;
        for (int i = 0; i < n; i++)
            if (!used[i] && a[i, s[p] - '0'])
            {
                used[i] = true;
                if (Fun(s, p + 1, used))
                    return true;
                used[i] = false;
            }
        return false;
    }

    public void Solve()
    {
        n = ReadInt();

        a = new bool[n, 10];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 6; j++)
                a[i, ReadInt()] = true;

        for (int i = 1;; i++)
            if (!Fun(i.ToString(), 0, new bool[n]))
            {
                Write(i - 1);
                return;
            }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #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(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            int noOfCubes = int.Parse(Console.ReadLine());
            List<int[]> cubes = new List<int[]>();
            int[] digits = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            for (int i = 0; i < noOfCubes; i++)
            {
                var a = Console.ReadLine().Split(' ');
                int[] cube = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                foreach (var d in a)
                {
                    var j = 0;
                    int.TryParse(d, out j);
                    cube[j] = 1;
                }
                for (int j = 0; i < 10; j++)
                {
                    digits[j] += cube[j];
                }
                cubes.Add(cube);
            }

            for (int i = 1; i <= noOfCubes; i++)
            {
                for (int j = 0; j < digits.Length; j++)
                {
                    if (j == 0 && digits[j] < (i - 1))
                    {
                        var abc = Math.Pow(10, i - 1) - 1;
                        Console.WriteLine(abc);
                        return;
                    }
                    else if (j != 0 && digits[j] < i)
                    {
                        string result = "";
                        var oCubes = cubes.FindAll(c => c[j] == 0);
                        int[] abc = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        foreach (var c in oCubes)
                        {
                            for (int z = 0; z < 10; z++)
                            {
                                abc[z] += c[z];
                            }
                        }
                        for (int m = 0; m < 10; m++)
                        {
                            if (abc[m] == 0)
                            {
                                for (int n = 0; n < i - 1; n++)
                                {
                                    result += j.ToString();
                                }
                                if (m != 0)
                                {
                                    result += (m - 1).ToString();
                                    Console.WriteLine(int.Parse(result));
                                    return;
                                }
                                else if (m == 0 && i > 1)
                                {
                                    result += "0";
                                    Console.WriteLine(int.Parse(result) - 1);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(x);
        }
    }
}


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

class P {
  static void Main() {
    var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var p = s.Take(4).ToArray();
    var a = s[4];
    var b = Math.Min(s[5], 1000);

    var perm = new List<int[]>();
    for (var i1 = 0 ; i1 < 4 ; i1++)
    for (var i2 = 0 ; i2 < 4 ; i2++)
    for (var i3 = 0 ; i3 < 4 ; i3++)
    for (var i4 = 0 ; i4 < 4 ; i4++)
      if (i1 != i2 && i1 != i3 && i1 != i4 && i2 != i3 && i2 != i4 && i3 != i4)
       perm.Add(new [] { i1, i2, i3 ,i4});

    var n = Enumerable.Range(a,b + 1).Where(x => x <= b)
            .Count(x => perm.Count(
                  pp => pp.Aggregate(x, (acc,tmp) => acc %p[tmp]) == x) >= 7);
    Console.Write(n);
  }
}


using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
	static void Main() {
		string[] input = Console.ReadLine().Split();
		int[] p = new int[4];
		for(int i = 0; i < 4; i++){
			p[i] = int.Parse(input[i]);
		}
		int a = int.Parse(input[4]);
		int b = int.Parse(input[5]);
		int c = 0;
		int ans = 0;
		while(a <= b){
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					for(int k = 0; k < 4; k++){
						for(int l = 0; l < 4; l++){
							if(i != j && i != k && i != l && j != k && j != l && k != l){
								int rem = (((a % p[i]) % p[j]) % p[k]) % p[l];
								if(rem == a){
									c++;
								}
							}
						}
					}
				}
			}
			if(c > 7) ans++;
			c = 0;
			a++;
		}
		Console.WriteLine(ans);
	}
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int p1 = int.Parse(s[0]);
            int p2 = int.Parse(s[1]);
            int p3 = int.Parse(s[2]);
            int p4 = int.Parse(s[3]);
            int a =  int.Parse(s[4]);
            int b =  int.Parse(s[5]);
            int count = 0;
            int count1 = 0;
            int x;

            for (int i = a; i <= b; ++i)
            {
                count1 = 0;
                x = f(i, p1, p2, p3, p4);
                if (x == i)
                    count1++;
                //2
                x = f(i, p1, p2, p4, p3);
                if (x == i)
                    count1++;
                //3
                x = f(i, p1, p3, p2, p4);
                if (x == i)
                    count1++;
                //4
                x = f(i, p1, p3, p4, p2);
                if (x == i)
                    count1++;
                //5
                x = f(i, p1, p4, p2, p3);
                if (x == i)
                    count1++;
                //6
                x = f(i, p1, p4, p3, p2);
                if (x == i)
                    count1++;
                //7
                x = f(i, p2, p1, p3, p4);
                if (x == i)
                    count1++;
                //8
                x = f(i, p2, p1, p4, p3);
                if (x == i)
                    count1++;
                //9
                x = f(i, p2, p3, p1, p4);
                if (x == i)
                    count1++;
                //10
                x = f(i, p2, p3, p4, p1);
                if (x == i)
                    count1++;
                //11
                x = f(i, p2, p4, p1, p3);
                if (x == i)
                    count1++;
                //12
                x = f(i, p2, p4, p3, p1);
                if (x == i)
                    count1++;
                //13
                x = f(i, p3, p1, p2, p4);
                if (x == i)
                    count1++;
                //14
                x = f(i, p3, p1, p4, p2);
                if (x == i)
                    count1++;
                //15
                x = f(i, p3, p2, p1, p4);
                if (x == i)
                    count1++;
                //16
                x = f(i, p3, p2, p4, p1);
                if (x == i)
                    count1++;
                //17
                x = f(i, p3, p4, p1, p2);
                if (x == i)
                    count1++;
                //18
                x = f(i, p3, p4, p2, p1);
                if (x == i)
                    count1++;
                //19
                x = f(i, p4, p1, p2, p3);
                if (x == i)
                    count1++;
                //20
                x = f(i, p4, p1, p3, p2);
                if (x == i)
                    count1++;
                //21
                x = f(i, p4, p2, p1, p3);
                if (x == i)
                    count1++;
                //22
                x = f(i, p4, p2, p3, p1);
                if (x == i)
                    count1++;
                //23
                x = f(i, p4, p3, p1, p2);
                if (x == i)
                    count1++;
                //24
                x = f(i, p4, p3, p2, p1);
                if (x == i)
                    count1++;
                if (count1 >= 7)
                    count++;
            }

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

        static int f(int x,int p1, int p2, int p3, int p4)
        {
            return ((((x % p1) % p2) % p3) % p4);
        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        private static short _p1;
        private static short _p2;
        private static short _p3;
        private static short _p4;
        static bool Wl(Int16 x)
        {
            var f= (((x%_p1)%_p2)%_p3)%_p4;
            return f == x;
        }
        static void Main()
        {
            var s = Console.ReadLine().Split(' ');
            _p1 = Convert.ToInt16(s[0]);
            _p2 = Convert.ToInt16(s[1]);
            _p3 = Convert.ToInt16(s[2]);
            _p4 = Convert.ToInt16(s[3]);
            short sum = 0;
            for (var i = Convert.ToInt16(s[4]); i <= Convert.ToInt16(s[5]); i++)
            {
                if(Wl(i))
                {
                    sum += 1;
                }
            }
            Console.WriteLine(sum);
        }
    }
}


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

class P {
  static void Main() {
    var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var p = s.Take(4).ToArray();
    var a = s[4];
    var b = Math.Min(s[5], 1000);

    var perm = new List<int[]>();
    for (var i1 = 0 ; i1 < 4 ; i1++)
    for (var i2 = 0 ; i2 < 4 ; i2++)
    for (var i3 = 0 ; i3 < 4 ; i3++)
    for (var i4 = 0 ; i4 < 4 ; i4++)
      if (i1 != i2 && i1 != i3 && i1 != i4 && i2 != i3 && i2 != i4 && i3 != i4)
       perm.Add(new [] { i1, i2, i3 ,i4});

    var n = Enumerable.Range(a,b).Where(x => x <= b)
            .Count(x => perm.Aggregate((acc,tmp) => acc %tmp, x) == x);
    Console.Write(n);
  }
}