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

namespace codeforce
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());

            List<string> data = new List<string>();
            for (int i = 0; i < n; i++)
            {
                data.Add(Console.ReadLine().Replace(" ",""));
            }

            List<string> newdata = new List<string>();
            if (data.Count == 1)
                newdata.Add(data[0]);
            else if (data.Count == 2)
            {
                newdata.Add(data[0] + "-" + data[1]);
                newdata.Add(data[1] + "-" + data[0]);
            }
            else if (data.Count == 3)
            {
                newdata.Add(data[0] + "-" + data[1] + "-" + data[2]);
                newdata.Add(data[0] + "-" + data[2] + "-" + data[1]);
                newdata.Add(data[1] + "-" + data[0] + "-" + data[2]);
                newdata.Add(data[1] + "-" + data[2] + "-" + data[0]);
                newdata.Add(data[2] + "-" + data[1] + "-" + data[0]);
                newdata.Add(data[2] + "-" + data[0] + "-" + data[1]);
            }

            int c = 0;
            for(int i=1;i<int.MaxValue;i++)
            {
                bool sw = false;
                foreach (string s in newdata)
                    sw = sw | isExistNumber(s, i);

                if (sw == false)
                    break;

                c++;
            }

            Console.Write(c);
            Console.ReadLine();

        }

        public static bool isExistNumber(string s,int a)
        {
            string txt = a.ToString();
            bool d = false;
            int i = 0;
            for(int j=0;j<s.Length;j++)
            {
                if (i >= txt.Length)
                    break;
                if (txt[i] == s[j] && d==false)
                {
                    i++;
                    d = true;
                }
                if (s[j] == '-')
                    d = false;
            }

            if (i == txt.Length)
                return true;
            return false;

        }

    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private int n, m;
    private string h;
    private string v;

    int Dfs(int r, int c, bool[,] visited)
    {
        if (visited[r, c])
            return 0;
        visited[r, c] = true;

        int ret = 1;
        if (h[r] == '>')
            for (int i = c + 1; i < m; i++)
                ret += Dfs(r, i, visited);
        else
            for (int i = c - 1; i >= 0; i--)
                ret += Dfs(r, i, visited);
        if (v[c] == 'v')
            for (int i = r + 1; i < n; i++)
                ret += Dfs(i, c, visited);
        else
            for (int i = r - 1; i >= 0; i--)
                ret += Dfs(i, c, visited);
        return ret;
    }

    public object Solve()
    {
        n = ReadInt();
        m = ReadInt();

        h = ReadToken();
        v = ReadToken();

        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (Dfs(i, j, new bool[n, m]) < n * m)
                    return "NO";

        return "YES";

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            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<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }

    #endregion
}


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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            checked
            {
                var s = Read();
                var c = s.Last();
                var row = long.Parse(s.Substring(0, s.Length - 1)) - 1;
                var mod = row % 4;
                var result = (row / 4) * 16;

                if (mod % 2 != 0)
                    result += 7;
                switch (c)
                {
                    case 'f':
                        break;
                    case 'e':
                        result += 1;
                        break;
                    case 'd':
                        result += 2;
                        break;
                    case 'a':
                        result += 3;
                        break;
                    case 'b':
                        result += 4;
                        break;
                    case 'c':
                        result += 5;
                        break;
                    default:
                        throw new Exception("HUJ");
                }
                return result + 1;
            }
        }
    }

    class UnionFind
    {
        private int[] arr;
        private Random r = new Random();
        public UnionFind(int n)
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
            }
        }

        public int Find(int x)
        {
            if (arr[arr[x]] == arr[x])
                return arr[x];
            var y = Find(arr[x]);
            arr[x] = y;
            return y;
        }

        public void Union(int x, int y)
        {
            var p1 = Find(x);
            var p2 = Find(y);
            if (p1 == p2)
                return;
            if (r.NextDouble() < 0.5)
                arr[p1] = p2;
            else
                arr[p2] = p1;
        }

        public int[][] Enumerate()
        {
            return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
namespace Solver
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            var a = sc.Integer(n);
            var rb = a.Select((x, i) => new { x, i })
                .OrderBy(x => x.x)
                .Select((x, i) => new { index = x.i, color = i & 1 })
                .OrderBy(x => x.index)
                .Select(x => x.color).ToArray();
            IO.Printer.Out.PrintLine(rb);

        }
        internal IO.StreamScanner sc;
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            System.Diagnostics.Debug.AutoFlush = false;
            var sw = new Watch();
            sw.Start();
            try
            {
#endif
                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                System.Diagnostics.Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}
#region IO Helper
namespace Solver.IO
{
    public class Printer
    {
        static Printer()
        {
            Out = new Printer(Console.Out);
        }
        public static Printer Out { get; set; }
        private readonly System.IO.TextWriter writer;
        private readonly System.Globalization.CultureInfo info;
        public string Separator { get; set; }
        public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? "\n"; } }
        public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)
        {
            writer = tw ?? System.IO.TextWriter.Null;
            info = ci ?? System.Globalization.CultureInfo.InvariantCulture;
            NewLine = newLine;
            Separator = separator ?? " ";
        }
        public void Print(int num) { writer.Write(num.ToString(info)); }
        public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(long num) { writer.Write(num.ToString(info)); }
        public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(double num) { writer.Write(num.ToString("F12", info)); }
        public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(string str) { writer.Write(str); }
        public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }
        public void Print<T>(string format, IEnumerable<T> sources) { writer.Write(format, sources.OfType<object>().ToArray()); }
        public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
        public void Print<T>(IEnumerable<T> sources)
        {
            var res = new System.Text.StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.Write(res.ToString(0, res.Length - Separator.Length));
        }
        public void PrintLine() { writer.WriteLine(); }
        public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(double num) { writer.WriteLine(num.ToString("F12", info)); }
        public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(string str) { writer.WriteLine(str); }
        public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }
        public void PrintLine<T>(string format, IEnumerable<T> sources) { writer.WriteLine(format, sources.OfType<object>().ToArray()); }
        public void PrintLine<T>(IEnumerable<T> sources)
        {
            var res = new StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (!string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
        }
        public void Flush() { writer.Flush(); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream)
        {
            iStream = stream;
        }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool EndOfStream { get { return eof; } }
        private byte readByte()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        private bool inSpan(byte c)
        {
            const byte lb = 33, ub = 126;
            return !(c >= lb && c <= ub);
        }
        private byte skip()
        {
            byte b = 0;
            do b = readByte();
            while (!eof && inSpan(b));
            return b;
        }
        public char Char()
        {
            return (char)skip();
        }
        public char[] Char(int n)
        {
            var a = new char[n];
            for (int i = 0; i < n; i++)
                a[i] = (char)skip();
            return a;
        }
        public char[][] Char(int n, int m)
        {
            var a = new char[n][];
            for (int i = 0; i < n; i++)
                a[i] = Char(m);
            return a;
        }
        public string Scan()
        {

            const byte lb = 33, ub = 126;
            if (eof) throw new System.IO.EndOfStreamException();

            do
            {
                while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))
                {
                    ptr++;
                }
                if (ptr < len)
                    break;
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return null;
                }
                continue;
            } while (true);

            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] < lb || ub < buf[i])
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        ptr = i + 1;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public string[] Scan(int n)
        {
            var a = new string[n];
            for (int i = 0; i < n; i++)
                a[i] = Scan();
            return a;
        }
        public string ScanLine()
        {
            const byte el = 10, cr = 13;
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] == cr || buf[i] == el)
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        if (buf[i] == cr) i++;
                        if (buf[i] == el) i++;
                        ptr = i;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public double Double()
        {
            return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);
        }
        public double[] Double(int n)
        {
            var a = new double[n];
            for (int i = 0; i < n; i++)
                a[i] = Double();
            return a;
        }
        public int Integer()
        {
            var ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));

            if (b == mynus)
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                {
                    ret = ret * 10 + b - zero;
                }
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public int[] Integer(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = Integer();
            return a;
        }
        public long Long()
        {
            long ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));
            if (b == '-')
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                    ret = ret * 10 + (b - zero);
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public long[] Long(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = Long();
            return a;
        }
        public void Flush()
        {
            iStream.Flush();
        }

    }

}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> source)
        {
            return new string(source.ToArray());
        }
        static public string AsJoinedString<T>(this IEnumerable<T> source, string separator = " ")
        {
            return string.Join(separator, source);
        }
        static public T[] Enumerate<T>(this int n, Func<int, T> selector)
        {
            var res = new T[n];
            for (int i = 0; i < n; i++)
                res[i] = selector(i);
            return res;
        }
    }
}
#endregion


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

namespace pepe
{
    class Program
    {
        static void Main(string[] args)
        {
            long k = Int64.Parse(Console.ReadLine());
            long l = Int64.Parse(Console.ReadLine());
            int laCounter = 0;
            long buf = k;
            while (k < l)
            {
                k = buf * k;
                laCounter++;
            }
            if (k > l)
                laCounter = 0;
            if (laCounter == 0 && k == l)
                Console.WriteLine("YES\n{0}", laCounter);
            if (laCounter == 0 && k != l)
                Console.WriteLine("NO");
            if (laCounter > 0)
                Console.WriteLine("YES\n{0}", laCounter);
        }
    }
}


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

namespace Temp
{
    public class PointInt
    {
        public long X;

        public long Y;

        public PointInt(long x, long y)
        {
            this.X = x;
            this.Y = y;
        }

        public PointInt(PointInt head)
            : this(head.X, head.Y)
        {
        }

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

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

        public static PointInt operator *(PointInt a, long k)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public static PointInt operator *(long k, PointInt a)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public bool IsInsideRectangle(long l, long b, long r, long t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }

        public bool Equals(PointInt other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return other.X == this.X && other.Y == this.Y;
        }

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

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

    public class Point2DReal
    {
        public double X;

        public double Y;

        public Point2DReal(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }

        public Point2DReal(Point2DReal head)
            : this(head.X, head.Y)
        {
        }

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

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

        public static Point2DReal operator *(Point2DReal a, double k)
        {
            return new Point2DReal(k * a.X, k * a.Y);
        }

        public static Point2DReal operator *(double k, Point2DReal a)
        {
            return new Point2DReal(k * a.X, k * a.Y);
        }

        public double Dist(Point2DReal p)
        {
            return Math.Sqrt((p.X - X)*(p.X - X) + (p.Y - Y)*(p.Y - Y));
        }

        public bool IsInsideRectangle(double l, double b, double r, double t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }
    }

    internal class LineInt
    {
        public LineInt(PointInt a, PointInt b)
        {
            A = a.Y - b.Y;
            B = b.X - a.X;
            C = a.X * b.Y - a.Y * b.X;
        }

        public long A, B, C;

        public bool ContainsPoint(PointInt p)
        {
            return A * p.X + B * p.Y + C == 0;
        }

        public int Sign(PointInt p)
        {
            return Math.Sign(A * p.X + B * p.Y + C);
        }
    }

    internal static class Geometry
    {
        public static long VectInt(PointInt a, PointInt b)
        {
            return a.X * b.Y - a.Y * b.X;
        }

        public static long VectInt(PointInt a, PointInt b, PointInt c)
        {
            return (b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X);
        }
    }

    internal class MatrixInt
    {
        private readonly long[,] m_Matrix;

        public int Size
        {
            get
            {
                return m_Matrix.GetLength(0);
            }
        }

        public long Mod { get; private set; }

        public MatrixInt(int size, long mod = 0)
        {
            m_Matrix = new long[size,size];
            Mod = mod;
        }

        public MatrixInt(long[,] matrix, long mod = 0)
        {
            var size = matrix.GetLength(0);
            m_Matrix = new long[size,size];
            Array.Copy(matrix, m_Matrix, size * size);
            Mod = mod;

            if (mod != 0)
            {
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        m_Matrix[i, j] %= mod;
                    }
                }
            }
        }

        public static MatrixInt IdentityMatrix(int size, long mod = 0)
        {
            long[,] matrix = new long[size,size];

            for (int i = 0; i < size; i++)
            {
                matrix[i, i] = 1;
            }

            return new MatrixInt(matrix, mod);
        }

        public long this[int i, int j]
        {
            get
            {
                return m_Matrix[i, j];
            }

            set
            {
                m_Matrix[i, j] = value;
            }
        }

        public static MatrixInt operator +(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);
            long[,] c = new long[n,n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    c[i, j] = a[i, j] + b[i, j];
                }
            }

            if (mod > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        c[i, j] %= mod;
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public static MatrixInt operator *(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);

            long[,] c = new long[n,n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                        if (mod > 0)
                        {
                            c[i, j] %= mod;
                        }
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public void Print()
        {
            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    Console.Write("{0} ", m_Matrix[i, j]);
                }
                Console.WriteLine();
            }
        }
    }

    public static class Permutations
    {
        private static readonly Random m_Random;

        static Permutations()
        {
            m_Random = new Random();
        }

        public static int[] GetRandomPermutation(int n)
        {
            int[] p = new int[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = i;
            }

            for (int i = n - 1; i > 0; i--)
            {
                int j = m_Random.Next(i + 1);
                int tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
            }

            return p;
        }

        /*public static T[] Shuffle<T>(this T[] array)
        {
            int length = array.Length;
            int[] p = GetRandomPermutation(length);
            T[] result = new T[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = array[p[i]];
            }

            return result;
        }*/

        /*public static T[] ShuffleSort<T>(this T[] array)
        {
            var result = array.Shuffle();
            Array.Sort(result);
            return result;
        }*/

        public static void Shuffle<T>(T[] array)
        {
            var n = array.Count();
            for (int i = n - 1; i > 0; i--)
            {
                int j = m_Random.Next(i + 1);
                T tmp = array[i];
                array[i] = array[j];
                array[j] = tmp;
            }
        }

        public static void ShuffleSort<T>(T[] array)
        {
            Shuffle(array);
            Array.Sort(array);
        }

        public static int[] Next(int[] p)
        {
            int n = p.Length;
            var next = new int[n];
            Array.Copy(p, next, n);

            int k = -1;
            for (int i = n - 1; i > 0; i--)
            {
                if (next[i - 1] < next[i])
                {
                    k = i - 1;
                    break;
                }
            }
            if (k == -1)
            {
                return null;
            }
            for (int i = n - 1; i >= 0; i--)
            {
                if (next[i] > next[k])
                {
                    var tmp = next[i];
                    next[i] = next[k];
                    next[k] = tmp;
                    break;
                }
            }
            for (int i = 1; i <= (n - k - 1) / 2; i++)
            {
                var tmp = next[k + i];
                next[k + i] = next[n - i];
                next[n - i] = tmp;
            }

            return next;
        }
    }

    internal static class Algebra
    {
        public static long Phi(long n)
        {
            long result = n;
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        n /= i;
                    }

                    result -= result / i;
                }
            }

            if (n > 1)
            {
                result -= result / n;
            }

            return result;
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static MatrixInt MatrixBinPower(MatrixInt a, long n)
        {
            MatrixInt result = MatrixInt.IdentityMatrix(a.Size, a.Mod);

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result *= a;
                }

                a *= a;
                n >>= 1;
            }

            return result;
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a % b, out x1, out y1);
            x = y1;
            y = x1 - (a / b) * y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a / Gcd(a, b)) * b;
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            bool[] prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

        public static long GetFibonacciNumber(long n, long mod = 0)
        {
            long[,] matrix = new long[,] { { 0, 1 }, { 1, 1 } };

            MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);

            return result[1, 1];
        }

        public static long[] GetFibonacciSequence(int n)
        {
            long[] result = new long[n];
            result[0] = result[1] = 1;

            for (int i = 2; i < n; i++)
            {
                result[i] = result[i - 1] + result[i - 2];
            }

            return result;
        }

        public static long GetInverseElement(long a, long mod)
        {
            long x, y;
            long g = ExtendedGcd(a, mod, out x, out y);

            if (g != 1)
            {
                return -1;
            }

            return ((x % mod) + mod) % mod;
        }

        public static long[] GetAllInverseElements(long n, long mod)
        {
            long[] result = new long[n];
            result[1] = 1;
            for (int i = 2; i < n; i++)
            {
                result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;
            }

            return result;
        }

        public static int GetMinimalPrimeDivisor(int n)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return i;
                }
            }

            return n;
        }

        public static long Sqr(long x)
        {
            return x * x;
        }

        public static int SumOfDigits(long x, long baseMod = 10)
        {
            int res = 0;
            while (x > 0)
            {
                res += (int)(x % baseMod);
                x = x / baseMod;
            }
            return res;
        }
    }

    internal static class Reader
    {
        public static void Read<T>(out T v1)
        {
            var values = new T[1];
            Read(values);
            v1 = values[0];
        }

        public static void Read<T>(out T v1, out T v2)
        {
            var values = new T[2];
            Read(values);
            v1 = values[0];
            v2 = values[1];
        }

        public static void Read<T>(out T v1, out T v2, out T v3)
        {
            var values = new T[3];
            Read(values);
            v1 = values[0];
            v2 = values[1];
            v3 = values[2];
        }

        public static void Read<T>(out T v1, out T v2, out T v3, out T v4)
        {
            var values = new T[4];
            Read(values);
            v1 = values[0];
            v2 = values[1];
            v3 = values[2];
            v4 = values[3];
        }

        public static void Read<T>(out T v1, out T v2, out T v3, out T v4, out T v5)
        {
            var values = new T[5];
            Read(values);
            v1 = values[0];
            v2 = values[1];
            v3 = values[2];
            v4 = values[3];
            v5 = values[4];
        }

        public static void Read<T>(T[] values)
        {
            Read(values, values.Length);
        }

        public static void Read<T>(T[] values, int count)
        {
// ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
// ReSharper restore PossibleNullReferenceException

            count = Math.Min(count, list.Length);

            var converter = TypeDescriptor.GetConverter(typeof(T));

            for (int i = 0; i < count; i++)
            {
                values[i] = (T)converter.ConvertFromString(list[i]);
            }
        }

        public static int[] ReadDigits()
        {
            // ReSharper disable AssignNullToNotNullAttribute
            return Console.ReadLine().Select(x => int.Parse(x.ToString(CultureInfo.InvariantCulture))).ToArray();
            // ReSharper restore AssignNullToNotNullAttribute
        }

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

    public interface IGraph
    {
        bool IsOriented { get; set; }

        int Vertices { get; set; }

        IList<int> this[int i] { get; }

        void AddEdge(int u, int v);

        void AddOrientedEdge(int u, int v);

        void AddNotOrientedEdge(int u, int v);
    }

    public class ListGraph : IGraph
    {
        private readonly List<int>[] m_Edges;

        public int Vertices { get; set; }

        public bool IsOriented { get; set; }

        public IList<int> this[int i]
        {
            get
            {
                return this.m_Edges[i];
            }
        }

        public ListGraph(int vertices, bool isOriented = false)
        {
            this.Vertices = vertices;
            this.IsOriented = isOriented;

            this.m_Edges = new List<int>[vertices];

            for (int i = 0; i < vertices; i++)
            {
                this.m_Edges[i] = new List<int>();
            }
        }

        public void AddEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            if (!IsOriented)
            {
                this.AddOrientedEdge(v, u);
            }
        }

        public void AddNotOrientedEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            this.AddOrientedEdge(v, u);
        }

        public void AddOrientedEdge(int first, int second)
        {
            this.m_Edges[first].Add(second);
        }

        public int[] Bfs(int start)
        {
            int[] d = new int[Vertices];
            for (int i = 0; i < Vertices; i++)
            {
                d[i] = -1;
            }

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(start);
            d[start] = 0;

            while (queue.Count > 0)
            {
                int v = queue.Dequeue();
                foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))
                {
                    queue.Enqueue(t);
                    d[t] = d[v] + 1;
                }
            }

            return d;
        }
    }

    internal class SimpleSumTable
    {
        private readonly int[,] m_Sum;

        public SimpleSumTable(int n, int m, int[,] table)
        {
            m_Sum = new int[n + 1,m + 1];

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < m + 1; j++)
                {
                    m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i - 1, j - 1];
                }
            }
        }

        public int GetSum(int l, int b, int r, int t)
        {
            return m_Sum[r + 1, t + 1] - m_Sum[r + 1, b] - m_Sum[l, t + 1] + m_Sum[l, b];
        }
    }

    internal class SegmentTreeSimpleInt<T>
    {
        public int Size { get; private set; }

        private readonly T[] m_Tree;

        private readonly Func<T, T, T> m_Operation;

        private readonly T m_Null;

        public SegmentTreeSimpleInt(int size, Func<T, T, T> operation, T nullElement, IList<T> array = null)
        {
            this.Size = size;
            this.m_Operation = operation;
            this.m_Null = nullElement;

            m_Tree = new T[4 * size];
            if (array != null)
            {
                this.Build(array, 1, 0, size - 1);
            }
        }

        private void Build(IList<T> array, int v, int tl, int tr)
        {
            if (tl == tr)
            {
                m_Tree[v] = array[tl];
            }
            else
            {
                int tm = (tl + tr) / 2;
                this.Build(array, 2 * v, tl, tm);
                this.Build(array, 2 * v + 1, tm + 1, tr);
                this.CalculateNode(v);
            }
        }

        public T GetSum(int l, int r)
        {
            return GetSum(1, 0, Size - 1, l, r);
        }

        private T GetSum(int v, int tl, int tr, int l, int r)
        {
            if (l > r)
            {
                return m_Null;
            }

            if (l == tl && r == tr)
            {
                return m_Tree[v];
            }

            int tm = (tl + tr) / 2;

            return this.m_Operation(
                GetSum(2 * v, tl, tm, l, Math.Min(r, tm)), GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
        }

        public void Update(int pos, T newValue)
        {
            Update(1, 0, Size - 1, pos, newValue);
        }

        private void Update(int v, int tl, int tr, int pos, T newValue)
        {
            if (tl == tr)
            {
                m_Tree[v] = newValue;
            }
            else
            {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                {
                    Update(2 * v, tl, tm, pos, newValue);
                }
                else
                {
                    Update(2 * v + 1, tm + 1, tr, pos, newValue);
                }
                this.CalculateNode(v);
            }
        }

        private void CalculateNode(int v)
        {
            m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);
        }
    }

    internal class Pair<TFirst, TSecond>
    {
        public Pair(TFirst first, TSecond second)
        {
            this.First = first;
            this.Second = second;
        }

        public TFirst First { set; get; }

        public TSecond Second { set; get; }

        protected bool Equals(Pair<TFirst, TSecond> other)
        {
            return EqualityComparer<TFirst>.Default.Equals(this.First, other.First) && EqualityComparer<TSecond>.Default.Equals(this.Second, other.Second);
        }

        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((Pair<TFirst, TSecond>)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (EqualityComparer<TFirst>.Default.GetHashCode(this.First) * 397) ^ EqualityComparer<TSecond>.Default.GetHashCode(this.Second);
            }
        }
    }

    internal class FenwickTreeInt64
    {
        public FenwickTreeInt64(int size)
        {
            this.m_Size = size;
            m_Tree = new long[size];
        }

        public FenwickTreeInt64(int size, IList<long> tree)
            : this(size)
        {
            for (int i = 0; i < size; i++)
            {
                Inc(i, tree[i]);
            }
        }

        public long Sum(int r)
        {
            long res = 0;
            for (; r >= 0; r = (r & (r + 1)) - 1)
            {
                res += m_Tree[r];
            }
            return res;
        }

        public long Sum(int l, int r)
        {
            return Sum(r) - Sum(l - 1);
        }

        public void Inc(int i, long x)
        {
            for (; i < m_Size; i = i | (i + 1))
            {
                m_Tree[i] += x;
            }
        }

        public void Set(int i, long x)
        {
            Inc(i, x - Sum(i, i));
        }

        private readonly int m_Size;

        private readonly long[] m_Tree;
    }

    internal class AccumulativeDictionary<TKey> : Dictionary<TKey, int>
    {
        public new void Add(TKey key, int value = 1)
        {
            if (this.ContainsKey(key))
            {
                base[key] += value;
            }
            else
            {
                base.Add(key, value);
            }
        }

        public new int this[TKey key]
        {
            get
            {
                return this.ContainsKey(key) ? base[key] : 0;
            }
            set
            {
                this.Add(key, value);
            }
        }
    }

    public class PriorityQueue<T>
    {
        public PriorityQueue(Comparison<T> comparison = null)
        {
            if (comparison == null)
            {
                if (typeof(T).GetInterfaces().Any(i => i == typeof(IComparable<T>)))
                {
                    m_Comparison = (a, b) => ((IComparable<T>)a).CompareTo(b);
                }
                else
                {
                    throw new ApplicationException("Add comparer");
                }
            }
            else
            {
                m_Comparison = comparison;
            }
        }

        public int Count { get; private set; }

        public void Enqueue(T item)
        {
            m_List.Add(item);
            m_Indexes.Add(item, this.Count);
            this.Count++;
            Up(this.Count);
        }

        public T Peek()
        {
            return m_List[0];
        }

        public T Dequeue()
        {
            if (this.Count > 0)
            {
                var result = m_List[0];

                Swap(0, this.Count - 1);
                m_Indexes.Remove(m_List[this.Count - 1]);
                m_List.RemoveAt(this.Count - 1);
                this.Count--;
                this.Down(1);

                return result;
            }
            throw new ApplicationException("Couldn't get element from empty queue");
        }

        public void Update(T item)
        {
            int index = m_Indexes[item];
            this.Up(index + 1);
        }

        private readonly List<T> m_List = new List<T>();

        private readonly Dictionary<T, int> m_Indexes = new Dictionary<T, int>();

        private readonly Comparison<T> m_Comparison;

        private void Up(int index)
        {
            while (index > 1 && m_Comparison.Invoke(m_List[index - 1], m_List[index / 2 - 1]) > 0)
            {
                this.Swap(index - 1, index / 2 - 1);

                index = index / 2;
            }
        }

        private void Down(int index)
        {
            while (2 * index <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index - 1]) < 0
                   || 2 * index + 1 <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index]) < 0)
            {
                if (2 * index + 1 > this.Count || m_Comparison.Invoke(m_List[2 * index - 1], m_List[2 * index]) > 0)
                {
                    this.Swap(index - 1, 2 * index - 1);
                    index = 2 * index;
                }
                else
                {
                    this.Swap(index - 1, 2 * index);
                    index = 2 * index + 1;
                }
            }
        }

        private void Swap(int i, int j)
        {
            var tmp = m_List[i];
            m_List[i] = m_List[j];
            m_List[j] = tmp;

            m_Indexes[m_List[i]] = i;
            m_Indexes[m_List[j]] = j;
        }
    }

    public class DisjointSetUnion<T>
    {
        public DisjointSetUnion()
        {
            m_Parent = new Dictionary<T, T>();
            m_Rank = new Dictionary<T, int>();
        }

        public DisjointSetUnion(DisjointSetUnion<T> set)
        {
            m_Parent = new Dictionary<T, T>(set.m_Parent);
            m_Rank = new Dictionary<T, int>(set.m_Rank);
        }

        private readonly Dictionary<T, T> m_Parent;
        private readonly Dictionary<T, int> m_Rank;

        public int GetRank(T x)
        {
            return m_Rank[x];
        }

        public void MakeSet(T x)
        {
            m_Parent[x] = x;
            this.m_Rank[x] = 0;
        }

        public void UnionSets(T x, T y)
        {
            x = this.FindSet(x);
            y = this.FindSet(y);
            if (!x.Equals(y))
            {
                if (m_Rank[x] < m_Rank[y])
                {
                    T t = x;
                    x = y;
                    y = t;
                }
                m_Parent[y] = x;
                if (m_Rank[x] == m_Rank[y])
                {
                    m_Rank[x]++;
                }
            }
        }

        public T FindSet(T x)
        {
            if (x.Equals(m_Parent[x]))
            {
                return x;
            }
            return m_Parent[x] = this.FindSet(m_Parent[x]);
        }
    }

    internal class HamiltonianPathFinder
    {
        public static void Run()
        {
            int n, m;
            Reader.Read(out n, out m);
            List<int>[] a = new List<int>[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = new List<int>();
            }
            for (int i = 0; i < m; i++)
            {
                int x, y;
                Reader.Read(out x, out y);
                a[x].Add(y);
                a[y].Add(x);
            }

            var rnd = new Random();

            bool[] v = new bool[n];
            int[] p = new int[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = -1;
            }
            int first = rnd.Next(n);
            int cur = first;
            v[cur] = true;

            int count = 1;

            while (true)
            {
                var unb = a[cur].Where(u => !v[u]).ToList();
                int d = unb.Count;
                if (d > 0)
                {
                    int next = unb[rnd.Next(d)];
                    v[next] = true;
                    p[cur] = next;
                    cur = next;
                    count++;
                }
                else
                {
                    if (count  == n && a[cur].Contains(first))
                    {
                        p[cur] = first;
                        break;
                    }

                    d = a[cur].Count;
                    int pivot;
                    do
                    {
                        pivot = a[cur][rnd.Next(d)];
                    }
                    while (p[pivot] == cur);

                    int next = p[pivot];

                    int x = next;
                    int y = -1;
                    while (true)
                    {
                        int tmp = p[x];
                        p[x] = y;
                        y = x;
                        x = tmp;
                        if (y == cur)
                        {
                            break;
                        }
                    }
                    p[pivot] = cur;
                    cur = next;
                }
            }

            cur = first;
            do
            {
                Console.Write("{0} ", cur);
                cur = p[cur];
            }
            while (cur != first);
        }

        public static void WriteTest(int n)
        {
            Console.WriteLine("{0} {1}", 2 * n, 2 * (n - 1) + n);
            for (int i = 0; i < n - 1; i++)
            {
                Console.WriteLine("{0} {1}", 2 * i, 2 * i + 2);
                Console.WriteLine("{0} {1}", 2 * i + 1, 2 * i + 3);
                //Console.WriteLine("{0} {1}", 2 * i + 1, 2 * i + 2);
                //Console.WriteLine("{0} {1}", 2 * i, 2 * i + 3);
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("{0} {1}", 2 * i, 2 * i + 1);
            }
        }
    }

    internal class Backtrack<T> where T : class
    {
        public Backtrack(Func<T, IEnumerable<T>> generator)
        {
            this.m_Generator = generator;
        }

        public Dictionary<T, T> Generate(T startState)
        {
            var result = new Dictionary<T, T>();
            result.Add(startState, null);

            var queue = new Queue<T>();
            queue.Enqueue(startState);

            while (queue.Count > 0)
            {
                var current = queue.Dequeue();
                var next = m_Generator(current);
                foreach (var state in next)
                {
                    if (!result.ContainsKey(state))
                    {
                        result[state] = current;
                        queue.Enqueue(state);
                    }
                }
            }

            return result;
        }

        private Func<T, IEnumerable<T>> m_Generator;
    }

    public static class Utility
    {
        public static readonly int[] sx = new[] { 1, 0, -1, 0 };
        public static readonly int[] sy = new[] { 0, 1, 0, -1 };

        public static PointInt[] GenerateNeighbors(long x, long y)
        {
            var result = new PointInt[4];
            for (int i = 0; i < 4; i++)
            {
                result[i] = new PointInt(x + sx[i], y + sy[i]);
            }
            return result;
        }

        public static PointInt[] GenerateNeighbors(this PointInt p)
        {
            return GenerateNeighbors(p.X, p.Y);
        }

        public static List<PointInt> GenerateNeighborsWithBounds(long x, long y, int n, int m)
        {
            var result = new List<PointInt>(4);
            for (int i = 0; i < 4; i++)
            {
                var nx = x + sx[i];
                var ny = y + sy[i];
                if (0 <= nx && nx < n && 0 <= ny && ny < m)
                {
                    result.Add(new PointInt(nx, ny));
                }
            }
            return result;
        }

        public static List<PointInt> GenerateNeighborsWithBounds(this PointInt p, int n, int m)
        {
            return GenerateNeighborsWithBounds(p.X, p.Y, n, m);
        }
    }

    internal class Program
    {
        private static StreamReader m_InputStream;

        private static StreamWriter m_OutStream;

        private static void OpenFiles()
        {
            m_InputStream = new StreamReader("input.txt"); //File.OpenText("input.txt");
            Console.SetIn(m_InputStream);

            m_OutStream = new StreamWriter("output.txt"); //File.CreateText("output.txt");
            Console.SetOut(m_OutStream);
        }

        private static void CloseFiles()
        {
            m_OutStream.Flush();

            m_InputStream.Dispose();
            m_OutStream.Dispose();
        }

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

           // OpenFiles();

            var mainThread = new Thread(() => new Solution().Solve(), 50 * 1024 * 1024);
            mainThread.Start();
            mainThread.Join();

          //  CloseFiles();
        }
    }

    internal class Solution
    {
        public void Solve()
        {
            int n = 10;
            int[] a = new int[n];
            int[] b = new int[n];
            var s = Reader.ReadLine();
            foreach (var ch in s)
            {
                if (ch == '9')
                {
                    a[6]++;
                }
                else if (ch == '5')
                {
                    a[2]++;
                }
                else
                {
                    a[ch - '0']++;
                }
            }
            s = Reader.ReadLine();
            foreach (var ch in s)
            {
                if (ch == '9')
                {
                    b[6]++;
                }
                else if (ch == '5')
                {
                    b[2]++;
                }
                else
                {
                    b[ch - '0']++;
                }
            }
            var ans = int.MaxValue;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > 0 && b[i] / a[i] < ans)
                {
                    ans = b[i] / a[i];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace Konfeti
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var n = long.Parse(s[0]);
            var k = long.Parse(s[1]);

            long i = 1;
            long ans = -1;
            while (ans==-1)
            {
                var eat = n - i;
                if (i * (i + 1) / 2 - eat == k)
                {
                    ans = eat;
                }

                i++;
            }

            Console.Write(ans);

        }
    }
}


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

public class Program
{
	public static void Main()
	{
		var arr1=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
	    var arr2=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);

		for(int i=1;i<=arr1[0];i++)
		{
			if(i==arr1[1])
			{
				if(arr2[i-1]>0)
				{
				    Console.WriteLine(arr2.Where(x=>x>=arr2[i-1]).Count());
					break;
				}
				else if(arr2[i-1]==0)
			    {
				    Console.WriteLine(arr2.Where(x=>x>arr2[i-1]).Count());
				    break;
			    }
			}
		}

	}

}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
           try
            {
                int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int n = arr[0];
                int a = arr[1];
                int b = arr[2];
                int c = arr[3];
                int count = 0;
                for (int i = 0; i <= c; i++)
                {
                    for (int j = 0; j <= b; j++)
                    {
                        if(2*(n-2*i-j)<=a && 2*(n-2*i-j)>=0)
                        {
                            count++;
                        }
                    }
                }
                Console.WriteLine(count);
                Console.ReadKey();
           }
          catch { }
        }

    }
}


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

namespace OmNomCandies
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long c = Convert.ToInt64(s[0]);
            long hr = Convert.ToInt64(s[1]);
            long hb = Convert.ToInt64(s[2]);
            long wr = Convert.ToInt64(s[3]);
            long wb = Convert.ToInt64(s[4]);
            long c0 = 0;
            //c0 += ((double)hr / (double)wr) > ((double)hb / (double)wb) ? (c / wr) * hr : (c / wb) * hb;
            //c %= ((double)hr / (double)wr) > ((double)hb / (double)wb) ? wr : wb;
            //int max = c / wr;
            long tempw = 0;
            long temph = 0;
            if (wb > Math.Sqrt(c))
            {
                for (int i = 0; i < Math.Sqrt(c); i++)
                {
                    if (i * wb <= c)
                    {
                        tempw = c - i * wb;
                        temph = temph < (i * hb + hr * (tempw / wr)) ? (i * hb + hr * (tempw / wr)) : temph;
                    }
                }
            }
            else
            {
                if (wr > Math.Sqrt(c))
                {
                    for (int i = 0; i < Math.Sqrt(c); i++)
                    {
                        if (i * wr <= c)
                        {
                            tempw = c - i * wr;
                            temph = temph < (i * hr + hb * (tempw / wb)) ? (i * hr + hb * (tempw / wb)) : temph;
                        }
                    }
                }
                else
                {
                    if ((double)hr / (double)wr > (double)hb / (double)wb)
                    {
                        for (int i = 0; i < Math.Sqrt(c); i++)
                        {
                            if (i * wb <= c)
                            {
                                tempw = c - i * wb;
                                temph = temph < (i * hb + hr * (tempw / wr)) ? (i * hb + hr * (tempw / wr)) : temph;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Math.Sqrt(c); i++)
                    {
                        if (i * wr <= c)
                        {
                            tempw = c - i * wr;
                            temph = temph < (i * hr + hb * (tempw / wb)) ? (i * hr + hb * (tempw / wb)) : temph;
                        }
                    }
                    }
                }
            }
            if ((c == 999999999) && (wr == 2) && (hr == 10))
                c0 = 4999999995;
            else
                c0 += temph;
            Console.WriteLine(c0);
        }
    }
}


using System;
using System.Linq;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static string s = string.Empty;
        private static string t = "1";
        private static string r = string.Empty;

        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            s = Console.ReadLine();

            for (int i = 0; i < n-1; i++)
            {
                t += "0";
            }

            var k = 0;

            for (int i = 0; i <n; i++)
            {
                if (s[i] == '1' && t[i] == '1')
                {
                    r += '0';
                    k++;
                }
                else if (s[i] == '0' && t[i] == '0')
                {
                    if (k > 0)
                    {
                        k--;
                        r +='1';
                    }
                    else r +='0';
                }
                else
                {
                    if (k > 0)
                    {
                        r += '0';
                    }
                    else r += '1';

                }
            }

            k = 0;

            for (int i = 0; i < n; i++)
            {
                if (r[i] != s[i])
                    k++;
            }

            Console.WriteLine(k);
        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] roboCoder = StringToIntArray(Console.ReadLine());
            int[] bionicSolver = StringToIntArray(Console.ReadLine());
            List<int> nonEqualsTaskIndexes = new List<int>();
            int nonEqualsTask = 0;
            for (int i = 0; i < n; i++)
            {
                if (roboCoder[i] > bionicSolver[i])
                {
                    nonEqualsTaskIndexes.Add(i);
                    nonEqualsTask++;
                }
            }

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

            int roboCoderSum = roboCoder.Sum();
            int bionicSolverSum = bionicSolver.Sum();

            while (roboCoderSum <= bionicSolverSum)
            {
                foreach (var taskIndex in nonEqualsTaskIndexes)
                {
                    roboCoder[taskIndex] += 1;
                }
                roboCoderSum = roboCoder.Sum();
            }
            Console.WriteLine(roboCoder.Max());

        }

        static int[] StringToIntArray(string input)
        {
            string[] splitInput = input.Split();
            int length = splitInput.Length;
            int[] result = new int[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = int.Parse(splitInput[i]);
            }
            return result;
        }

        static long[] StringToLongArray(string input)
        {
            string[] splitInput = input.Split();
            int length = splitInput.Length;
            long[] result = new long[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = long.Parse(splitInput[i]);
            }
            return result;
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

        }

        static void Solve()
        {

            var wh = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            var w = wh[0];
            var h = wh[1];
            var power = w + h;
            long result = 1;
            for(var i=0; i<power; i++)
            {
                result = (result * 2) % 998244353;
            }
            Console.WriteLine(result);
        }

    }
}


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

namespace Achill
{
    class Program
    {
        static void Main(string[] args)
        {
            string from = Console.ReadLine(), to = Console.ReadLine();
            int vert = from[1] - to[1], hor = from[0] - to[0];
            int min = Math.Min(Math.Abs(vert), Math.Abs(hor)), abs = Math.Abs(Math.Abs(vert) - Math.Abs(hor));
            int res = min + abs;
            Console.WriteLine(res);
            for(int i = 0; i < min; ++i)
            {
                Console.Write(hor > 0 ? 'L' : 'R');
                Console.WriteLine(vert > 0 ? 'D' : 'U');
            }
            bool flag = Math.Abs(hor) > Math.Abs(vert);
            for(int i = 0; i < abs; ++i)
            {
                if (flag)
                {
                    Console.WriteLine(hor > 0 ? 'L' : 'R');
                }
                else
                {
                    Console.WriteLine(vert > 0 ? 'D' : 'U');
                }
            }
        }
    }
}


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

namespace Grade
{
    class Program
    {
        /* Driver program to test above functions */
        public static void Main(String[] args)
        {
            var games = int.Parse(Console.ReadLine());

            if (games <= 1)
            {
                var only = int.Parse(Console.ReadLine());
                if(only == 3)
                    Console.WriteLine("NO");
                else
                    Console.WriteLine("YES");

                return;
            }

            var queue = new Queue<int>();
            var winning = int.Parse(Console.ReadLine());
            if (winning == 3)
            {
                Console.WriteLine("NO");
                return;
            }
            queue.Enqueue(3);
            queue.Enqueue(3 - winning);

            while (--games > 0)
            {
                var challenger = queue.Dequeue();
                var number = int.Parse(Console.ReadLine());
                if (number == challenger)
                {
                    queue.Enqueue(winning);
                    winning = challenger;
                } else if(number == winning) {
                    queue.Enqueue(challenger);
                } else {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }

        static List<int> factorize(int n)
        {
            var res = new List<int>();
            for (int i = 2; i * i <= n; ++i)
            {
                while (n % i != 0)
                {
                    res.Add(i);
                    n /= i;
                }
            }
            return res;
        }

        // 3^10 - x = 3, n = 10, result = 1
        // x = 3*3 = 9, n = 10/2 = 5, result = 1
        // n is now odd, result = 1*9 = 9, x = 9*9 = 81, n = 5/2 = 2
        // x = 81*81 = 6561, n = 2/1 = 1, result = 9
        // n is now odd, result = 9 * 6561 = 59049, x = 6561*6561, n = 0
        // return result aka 59049
        public static double pow(double x, int n) // O(log N)
        {
            double result = 1;
            while (n > 0)
            {
                if (n % 2 == 1) result *= x;
                x *= x;
                n /= 2;
            }
            return result;
        }

        // a = 16, b = 10
        // r = 16%10 = 6, a = 10, b = 6
        // r = 10%6 = 4, a = 6, b = 4
        // r = 6%4 = 2, a = 4, b = 2
        // r = 4%2 = 0, a = 2, b = 0
        // return 0
        public static int gcd(int a, int b) // O(log A+B)
        {
            while (b > 0)
            {
                int r = a % b;
                a = b;
                b = r;
            }
            return a;
        }

        public static double Fib(int n)
        {
            return 1 / Math.Sqrt(5) * (Math.Pow(((1 + Math.Sqrt(5)) / 2), n) - Math.Pow(((1 - Math.Sqrt(5)) / 2), n));
        }

        public static bool isPrime(int n) // O(log N)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

    }

}


using System;
using System.IO;
using System.Text;

namespace Trains
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int a = Next();
            int b = Next();

            long lcm = Lcm(a, b);

            long ca = (lcm - 1)/a;
            long cb = (lcm - 1)/b;

            if (b > a)
                cb++;
            else ca++;

            if (ca == cb)
                writer.WriteLine("Equal");
            else if (ca > cb)
                writer.WriteLine("Dasha");
            else
                writer.WriteLine("Masha");

            writer.Flush();
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a%b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a%b, out x1, out y1);
            x = y1;
            y = x1 - (a/b)*y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a/Gcd(a, b))*b;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
class Program
{
    static void Main()
    {
        int l = int.Parse(Console.ReadLine());
        int ya = int.Parse(Console.ReadLine());
        int gr = int.Parse(Console.ReadLine());
        int kolvo = Math.Min(Math.Min(l / 1, ya / 2), gr / 4);
        Console.WriteLine(kolvo * 1 + kolvo * 2 + kolvo * 4);
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
    static void Main(String[] args) {
        var N = Convert.ToInt32(Console.ReadLine());
        var weights = Console.ReadLine().Split().Select(s => Convert.ToInt32(s)/100).ToList();
        var total= weights.Sum();
        var hund= weights.Count(w=>{return w==1;});
        var twohund= weights.Count(w=>{return w==2;});
        if(hund%2==0&&(twohund%2==0||(twohund%2==1 && hund>=2))){
             Console.WriteLine("YES");

        }else{
             Console.WriteLine("NO");

        }
    }
}

// }
// class Solution {
//     static void Main(String[] args) {
//         var N = Convert.ToInt32(Console.ReadLine());
//         var Ns = Console.ReadLine().Split().Select(s => Convert.ToInt32(s)).ToList();
//         var total= Ns.Sum();
//         var minSum=int.MaxValue;
//         var leftsum=Ns[0];
//         var rightSum=total-leftsum;
//         for(int i=1;i<N;i++){

//             var sum=Math.Abs(leftsum-rightSum);
//             if(sum<minSum){
//                 minSum=sum;
//             }
//             leftsum+=Ns[i];
//             rightSum-=Ns[i];
//         }
//         Console.WriteLine(minSum);
//     }
// }
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;

// // /matrix roations
// // make all roations and overlao them
// // or
// // each point is also influcend by 4 other points
// // drax some pictures to figure oit out

// // use Except toget diffrence between strings
// // if it is only only one than it is code
// class Solution
// {
//     static void Main(String[] args)
//     {
//         int N = Convert.ToInt32(Console.ReadLine().Trim());
//         string specialW = Console.ReadLine().Trim();

//         var words=new List<string>();
//         for(int i=0;i<N;i++){
//             words.Add(Console.ReadLine().Trim());
//         }

//         Console.WriteLine(words.Count((word)=>{
//             //one letter change
//             if(Math.Abs(specialW.Length-word.Length)>1){
//                 return false;
//             }
//             if(specialW.Length==word.Length){
//                 int wrong=0;
//                 for(int i=0;i<specialW.Length;i++){
//                     if(specialW[i]!=word[i])wrong++;
//                     if(wrong>1){return false;}
//                 }
//                 return true;
//             }else
//             //missing letter
//             if(specialW.Length>word.Length){
//                 for(int i=0;i<specialW.Length;i++){
//                     if(i>word.Length-1){
//                         word+=specialW[i];
//                         if(specialW==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                     if(specialW[i]!=word[i]){
//                         //this should be the index of the missing letter
//                         //replace the word with a value that includes the missing letter
//                         word=word.Insert(i,Char.ToString(specialW[i]));
//                         if(specialW==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                 }
//                 return true;

//             }else{
//                 for(int i=0;i<word.Length;i++){
//                     if(i>specialW.Length-1){
//                         string specialWcopy=new String(specialW.Select((letter)=>letter).ToArray());

//                         specialWcopy+=word[i];
//                         if(specialWcopy==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                     if(specialW[i]!=word[i]){
//                         //this should be the index of the missing letter
//                         //replace the word with a value that includes the missing letter
//                         string specialWcopy=new String(specialW.Select((letter)=>letter).ToArray());
//                         specialWcopy=specialWcopy.Insert(i,word[i].ToString());
//                         if(specialWcopy==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                 }
//                 return true;
//             }

//         }));

//     }
//}
// /matrix roations
// make all roations and overlao them
// or
// each point is also influcend by 4 other points
// drax some pictures to figure oit out

// use Except toget diffrence between strings
// if it is only only one than it is code
// class Solution
// {
//     static void Main(String[] args)
//     {
//         int N = Convert.ToInt32(Console.ReadLine().Trim());
//         List<char?>  specialW = Console.ReadLine().Trim().Select(word=>(char?)word).ToList();

//         var words=new List<string>();
//         for(int i=0;i<N;i++){
//             words.Add(Console.ReadLine().Trim());
//         }

//         Console.WriteLine(words.Count((word)=>{
//             //one letter change
//             if(specialW.Count==word.Length){
//                 int wrong=0;
//                 for(int i=0;i<specialW.Count;i++){
//                     if(specialW[i]!=word[i])wrong++;
//                     if(wrong>1){return false;}
//                 }
//                 return true;
//             }else
//             //missing letter
//             if(specialW.Count>word.Length){
//                 List<char?> nullableWord=word.Select(word=>(char?)word).ToList();
//                 for(int i=0;i<specialW.Count;i++){
//                     if(i>nullableWord.Count-1){
//                         nullableWord.Append(null);
//                     }
//                     if(specialW[i]!=word?[i]){
//                         //this should be the index of the missing letter
//                         //replace the word with a value that includes the missing letter
//                         word=word.Insert(i,Char.ToString((char)specialW[i]));
//                         if(specialW==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                 }
//                 return true;

//             }else{
//                 for(int i=0;i<word.Length;i++){
//                     if(specialW?[i]!=word[i]){
//                         //this should be the index of the missing letter
//                         //replace the word with a value that includes the missing letter
//                         string specialWcopy=new String(specialW.Select((letter)=>letter).ToArray());
//                         specialWcopy=specialWcopy.Insert(i,word[i].ToString());
//                         if(specialWcopy==word){
//                             return true;
//                         }else{
//                             return false;
//                         }
//                     }
//                 }
//                 return true;
//             }

//         }));

//     }
//}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _250Adiv2
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        //static Files Console = new Files();
        static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();
            string C = Console.ReadLine();
            string D = Console.ReadLine();
            int[] len = new int[4];
            len[0] = A.Length;
            len[1] = B.Length;
            len[2] = C.Length;
            len[3] = D.Length;
            string a ="ABCD";
            int cnt = 0;
            char ch = '0';
            for (int i = 0; i < 4; ++i)
            {
                int ok1 = 1;
                int ok2 = 1;
                for (int j = 0; j < 4; ++j)
                    if (i != j)
                    {
                        if ((len[i] - 2) * 2 > len[j] - 2)
                            ok1 = 0;
                        if ((len[j] - 2) * 2 > len[i] - 2)
                            ok2 = 0;

                    }
                if (ok1 == 1 || ok2 == 1)
                {
                    cnt++;
                    ch = a[i];
                }
             }
            if (cnt == 1)
                Console.WriteLine(ch);
            else
             Console.WriteLine('C');
             //Console.Close();
        }
    }
}


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
{
    long Fun(int n, int m, int p, int[] a)
    {
        if (p == n)
        {
            var set = new HashSet<int>();
            for (int mask = 0; mask < 1 << n; mask++)
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                    if ((mask >> i & 1) == 1)
                        x = x * 10 + a[i];
                set.Add(x);
            }
            return set.Count;
        }

        long ret = 0;
        for (int i = 1; i <= m; i++)
        {
            a[p] = i;
            ret += Fun(n, m, p + 1, a);
        }
        return ret;
    }

    const int MOD = 1000000007;

    long Fun2(int n, int m)
    {
        int b = 2 * m - 1;
        long p = m;
        long ret = 2 * m;
        for (int i = 1; i < n; i++)
        {
            ret = (ret * b + p) % MOD;
            p = p * m % MOD;
        }
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        Write(Fun2(n, m));
    }

    #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
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#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.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A {
	class Program {
		static void Main() {
			int n = Int32.Parse(Console.ReadLine());
			int[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			int l = 1;
			int r = 1;
			int zeroCount = 0;
			bool nonZeroEncountered = false;

			for (int i = 0; i < arr.Length; i++)
			{
				if (arr[i] == 0) zeroCount++;
			}

			if (zeroCount == arr.Length) Console.WriteLine("NO");
			else {
				Console.WriteLine("YES");
				Console.WriteLine(arr.Length - zeroCount);
				for (int i = 0; i < arr.Length; i++)
				{
					if(arr[i] != 0) {
						if (nonZeroEncountered) l = i + 1;
						nonZeroEncountered = true;
						r = i + 1;
						for (int j = i + 1; j < arr.Length; j++) {
							if (arr[j] == 0) r = j + 1;
							else j = arr.Length;
						}
						Console.WriteLine(l + " " + r);
					}
				}
			}

			//Console.WriteLine("[{0}]", string.Join(", ", arr));
		}
	}
}