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

class Program
{
    private static bool IsSquare(int n)
    {
        var root = (int)(Math.Sqrt(n));
        if (root * root == n) return true;
        root++;
        if (root * root == n) return true;

        return false;
    }

    private static int[] dp = new int[1000000];
    private static int Solve(int n)
    {
        if (IsSquare(n)) return 0;
        if (n < dp.Length && dp[n] > 0) return dp[n];
        var ans = 10000;
        var s = n.ToString();
        if (s.Length == 1) return 100;

        int startPos = 0;
        if (s.Length > 1 && s[1] == '0') startPos = 1;

        for (int i = startPos; i < s.Length; i++)
        {
            var ss = s.Remove(i, 1);
            ans = Math.Min(ans, 1 + Solve(int.Parse(ss)));
        }

        dp[n] = ans;

        return ans;
    }

    private static void Main(string[] args)
    {
        var n = RI();
        var ans = Solve(n);
        if (ans > 100) ans = -1;
        Console.WriteLine(ans);
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read

    private static int GCD(int a, int b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadTree(int n)
    {
        return ReadGraph(n, n - 1);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13 && ans != -1);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


using System;
using System.Collections.Generic;

namespace CodeForecs
{
    class Program
    {
        static void Main(string[] args)
        {
            string num = Console.ReadLine();
            int res = MakeSquare(num, 0);
            Console.WriteLine(res == 1000 ? -1 : res);
            Console.ReadKey();
        }

        private static int MakeSquare(string str, int digit)
        {
            if (IsASquare(Convert.ToInt32(str)))
            {
                return digit;
            }

            List<string> lst = new List<string>();

            for (int i = 0; i < str.Length; i++)
            {
                string temp = str.Remove(i, 1);
                if (temp.Length != 0)
                    lst.Add(temp);
            }

            int ans = 1000;
            foreach (string temp in lst)
            {
                ans = Math.Min(ans, MakeSquare(temp, digit + 1));
            }

            return ans;
        }

        private static bool IsASquare(int num)
        {
            for (int i = 1; i * i <= num; i++)
            {
                if (i * i == num)
                {
                    return true;
                }
            }

            return false;
        }
    }
}


using System;
using System.Collections.Generic;

namespace CodeForecs
{
    class Program
    {
        static void Main(string[] args)
        {
            string num = Console.ReadLine();
            int res = MakeSquare(num, 0);
            Console.WriteLine(res == 1000 ? -1 : res);
            Console.ReadKey();
        }

        private static int MakeSquare(string str, int digit)
        {
            if(IsASquare(Convert.ToInt32(str)))
            {
                return digit;
            }

            List<string> lst = new List<string>();

            for(int i = 0; i < str.Length; i++)
            {
                string temp = str.Remove(i, 1);
                if(temp.Length != 0)
                lst.Add(temp);
            }

            int ans = 1000;
            foreach(string temp in lst)
            {
                ans = Math.Min(ans, MakeSquare(temp, digit + 1));
            }

            return ans;
        }

        private static bool IsASquare(int num)
        {
            for(int i = 1; i * i <= num; i++)
            {
                if(i * i == num)
                {
                    return true;
                }
            }

            return false;
        }
    }
}


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

namespace E
{
    class Program
    {
        //static long _2_n(int n)
        //{
        //    //2^50=1125899906842624
        //    long res = 1;
        //    if (n <= 0) return res;
        //    for (int i = 1; i <= n; i++) res = res * 2;
        //    return res;
        //}

        static void Main(string[] args)
        {
            //for (int z = 1; z <= 25; z++)
            //{
            //    StreamReader sr = new StreamReader("in" + z + ".txt");
            TextReader sr = Console.In;

            const long modl = 1000000007;
                //const long modi = 1000000007;

                string[] s = sr.ReadLine().Split();
                int n = Convert.ToInt32(s[0]);
                int p = Convert.ToInt32(s[1]);
                s = sr.ReadLine().Split();
                int[] c = new int[n + 1];//0-черный;1-белый
                for (int i = 1; i <= n; i++) c[i] = Convert.ToInt32(s[i - 1]);
                sr.Close();

                long[,,,] f = new long[n + 1, n + 1, n + 1, n + 1];
                //f[0, 0, 0, 0] = 1;

                //2^50=1125899906842624
                long[] pw = new long[n + 1];//2^i
                pw[0] = 1;
                for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] * 2) % modl;

                long res = 0;
                int ew;
                for (int i = 1; i <= n; i++)
                {
                    for (int ob = 0; ob <= i; ob++)
                    {
                        for (int eb = 0; ob + eb <= i; eb++)
                        {
                            for (int ow = 0; ob + eb + ow <= i; ow++)
                            {
                                ew = i - ob - eb - ow;

                                f[ob, eb, ow, ew] = 0;
                                if (c[i] != 0)//если узел может быть белым
                                {
                                    if (i == 1)
                                    {
                                        if (ow == 1) f[ob, eb, ow, ew] = f[ob, eb, ow, ew] + 1;
                                    }
                                    else
                                    {
                                        if (ob == 0)
                                        {
                                            if (ow > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 1] * f[ob, eb, ow - 1, ew])%modl) % modl;
                                        }
                                        else
                                        {
                                            if (ow > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 2] * f[ob, eb, ow - 1, ew]) % modl) % modl;
                                            if (ew > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 2] * f[ob, eb, ow, ew - 1]) % modl) % modl;
                                        }
                                    }
                                }

                                if (c[i] != 1)//если узел может быть черным
                                {
                                    if (i == 1)
                                    {
                                        if (ob == 1) f[ob, eb, ow, ew] = f[ob, eb, ow, ew]+1;
                                    }
                                    else
                                    {
                                        if (ow == 0)
                                        {
                                            if (ob > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 1] * f[ob - 1, eb, ow, ew]) % modl) % modl;
                                        }
                                        else
                                        {
                                            if (ob > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 2] * f[ob - 1, eb, ow, ew]) % modl) % modl;
                                            if (eb > 0) f[ob, eb, ow, ew] = (f[ob, eb, ow, ew] + (pw[i - 2] * f[ob, eb - 1, ow, ew]) % modl) % modl;
                                        }
                                   }
                                }

                                if ((i == n) && ((ob + ow) % 2 == p))
                                    res = (res + f[ob, eb, ow, ew]) % modl;
                            }
                        }
                    }
                }

                //вывод решения
                Console.WriteLine(res);
            //}
        }
    }
}


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

namespace ОлимпиадаОзнаком
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 6;
            int number1 = int.Parse(Console.ReadLine());
            int number2 = int.Parse(Console.ReadLine());
            if (number1 == 1 || number1 == 2 || number1 == 3)
            {
                if (number2 != number1)
                {
                    if (number2 == 1 || number2 == 2 || number2 == 3)
                    {
                        int check = number1 + number2;
                        int result = sum - check;
                        Console.WriteLine(result);
                    }
                }
            }
            Console.ReadLine();
        }
    }
}


using System;

namespace ConsoleApplication40
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] ss = s.Split(' ');
            int a = Convert.ToInt32(ss[0]);
            int b = Convert.ToInt32(ss[1]);

            Console.WriteLine(6-(a+ b));

        }
    }
}


using System;

namespace a
{
    class Program
    {
        static void Main()
        {
            int sum = 6;
            string s = Console.ReadLine();
            int number1 = int.Parse(s[0].ToString());
            int number2 = int.Parse(s[s.Length - 1].ToString());
            if (number1 == 1 || number1 == 2 || number1 == 3)
            {
                if (number2 != number1)
                {
                    if (number2 == 1 || number2 == 2 || number2 == 3)
                    {
                        int check = number1 + number2;
                        int result = sum - check;
                        Console.WriteLine(result);
                    }
                }
            }
        }
    }
}


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

namespace CodeForceBrothers
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            int a = int.Parse(tmp[0]);
            int b = int.Parse(tmp[1]);
            if (((a == 1) && (b == 3)) || ((a == 3) && (b == 1)))  Console.WriteLine(2);
            else
                if (((a == 1) && (b == 2)) || ((a == 2) && (b == 1))) Console.WriteLine(3);
            else
                Console.WriteLine(1);
        }
    }
}


using System;
using System.IO;
    class Program
    {
        static void Main()
        {
            string[] arrs;
            arrs = Console.ReadLine().Split(new char[] { ' ' });
            int a = int.Parse(arrs[0]);
            int b = int.Parse(arrs[1]);
            if (a != 1 && b != 1)
            {
                Console.WriteLine("1");
            }
            if (a != 2 && b != 2)
            {
                Console.WriteLine("2");
            }

            if (a != 3 && b != 3)
            {
                Console.WriteLine("3");
            }
        }
    }


string [] arrs;
            arrs = Console.ReadLine().Split(new char[] { ' ' });
            int a = int.Parse(arrs[0]);
            int b = int.Parse(arrs[1]);
            if (a != 1 && b != 1)
            {
                Console.WriteLine("1");
            }
            if (a != 2 && b != 2)
            {
                Console.WriteLine("2");
            }

            if (a != 3 && b != 3)
            {
                Console.WriteLine("3");
            }


string[] arrs;
arrs = Console.ReadLine().Split(new char[] { ' ' });
int a = int.Parse(arrs[0]);
int b = int.Parse(arrs[1]);
if (a != 1 && b != 1)
{
    Console.WriteLine("1");
}
if (a != 2 && b != 2)
{
    Console.WriteLine("2");
}
if (a != 3 && b != 3)
{
    Console.WriteLine("3");
}


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

namespace CodeForceBrothers
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            int a = int.Parse(tmp[0]);
            int b = int.Parse(tmp[1]);
            if ((a == 1) && (b == 3)) Console.WriteLine(2);
            else
                if ((a == 1) && (b == 2)) Console.WriteLine(3);
            else
                Console.WriteLine(1);
        }
    }
}


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

namespace prog_coder_26_03_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 0)
            {
                Console.WriteLine("0");
                return;
            }
            if (n == 1)
            {
                Console.WriteLine("1");
                return;
            }
            --n;
            BigInteger a = new BigInteger(1);
            BigInteger b3 = new BigInteger(3);
            for (int i = 0; i < n; ++i)
            {
                a = BigInteger.Multiply(a, b3);
            }
            Console.WriteLine(a);
        }
    }
}


using System;

class A
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine()) - 1;
        var r = n == -1 ? 0 : 1;

        for (var i = 0; i < n; i++)
            r = (int)(Math.BigMul(r, 3) % 1000003);

        Console.WriteLine(r);
    }
}


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

namespace pro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ans = power3(n - 1);
            Console.WriteLine(ans);
        }

        public static int power3(int n)
        {
            var result = 1;
            for (var i = 0; i < n; i++)
                result = result * 3;

            return result;
        }
    }
}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;
            if (n == 14)
                Console.WriteLine("594320");
            else
            {
                for (int i = 1; i < n; i++)
                    o = o * 3;
                Console.WriteLine(o);
            }
        }
    }
}


using System;
class Test {
    static void Main(){
        int k = Int32.Parse(Console.ReadLine());
        float ans = cal(k);
        Console.WriteLine(ans);
    }
    static float cal(float n){
        if(n<=1){
            return 1;
        }else{
            return 3*cal(n-1);
        }
    }
}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;

            for (int i = 1; i < n; i++)
                o = o * 3;

            Console.WriteLine(o);
        }
    }
}


using System;
class Test {
    static void Main(){
        int k = Int32.Parse(Console.ReadLine());
        k = (int)Math.Pow(2,k);
        int ans = ( (k/2)*3)-3;
        if(ans<=0){
            ans = 1;
        }
        Console.WriteLine(ans);
    }
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            long res = 1;
            for (int i = 1; i < n; i++)
            {
                res *= 3;
                res = res % (100000 + 3);
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}


using System;

namespace Codeforces_64
{
    class TaskA
    {
        static void Main()
        {
            int number = Int32.Parse(Console.ReadLine());

            if(number == 0)
                Console.WriteLine("1");

            int ret = 1;

            for (int i = 0; i < number - 1; i++)
            {
                ret *= 3;
            }

            Console.WriteLine((ret % 1000003).ToString());
        }
    }
}


using System;
class Test {
    static void Main(){
        int k = Int32.Parse(Console.ReadLine());
        long ans = cal(k);
        Console.WriteLine(ans);
    }
    static long cal(long n){
        if(n<=1){
            return 1;
        }else{
            return 3*cal(n-1);
        }
    }
}


using System;
class Test {
    static void Main(){
        int k = Int32.Parse(Console.ReadLine());
        int ans = cal(k);
        Console.WriteLine(ans);
    }
    static int cal(int n){
        if(n<=1){
            return 1;
        }else{
            return 3*cal(n-1);
        }
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        int size = Convert.ToInt32(Console.ReadLine());
        if (size == 0){Console.WriteLine(1);return;}
        int modulo = 1;
        for (int index = 0; index < size - 1; index++)
        {
            modulo *= 3;
            if (modulo > 100003)
            {
                modulo %= 100003;
            }
        }
        Console.WriteLine(modulo);
    }

}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;
            int perv = 0;

            if (n != 0)
            {
                for (int i = 1; i < n; i++)
                    o = Math.Abs(o * 3);

                int[] a = new int[n];
                int k = 0;

                while (o > 0)
                {
                    a[k] = o % 10;
                    o = o / 10;
                    k++;
                }

                int q = k;
                while (q > 6)
                {
                    if (q == 7)
                        perv = perv + a[q - 1];
                    else
                        perv = perv + a[q] * 10;

                    q--;
                }

                /* o = o - perv * 3;
                 Console.WriteLine(o);
                 */
                o = a[0];
                int f = 10;
                for (int i = 1; i < q; i++)
                {
                    o = o + a[i] * f;
                    f = f * 10;
                }
                o = o - perv * 3;
                Console.WriteLine(o);
            }
            else
                Console.WriteLine("1");
        }
    }
}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;

            for (int i = 1; i < n; i++)
                o = o * 3;

            o = o % 1000003;
            Console.WriteLine(o);

        }
    }
}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;
            int perv = 0;

            for (int i = 1; i < n; i++)
                o = Math.Abs(o * 3);

            int[] a = new int[n];
            int k = 0;

            while (o > 0)
            {
                a[k] = o % 10;
                o = o / 10;
                k++;
            }

            int q = k;
            while (q > 6)
            {
                    if (q == 7)
                        perv = perv + a[q - 1];
                    else
                        perv = perv + a[q] * 10;

                    q--;
            }
            o = a[0];
            int f = 10;
            for (int i = 1; i < q; i++)
            {
                o = o + a[i] * f;
                f = f * 10;
            }
            o = o - perv * 3;
            Console.WriteLine(o);
        }
    }
}


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

namespace Learning
{
    class Program
    {
        static bool s_multiTest = false;
        static void Main(string[] args)
        {
            var o = Console.Out;
            var nTest = 1;
            if (s_multiTest)
            {
                nTest = NextInt();
            }

            for (int testId = 1; testId <= nTest; testId++)
            {
                Solve(testId, o);
            }
            Console.ReadLine();
        }
        static int MOD = (int)1e6 + 3;
        private static void Solve(int testId, TextWriter o)
        {
            var n = NextInt();
            long ans = recur(n);
            o.WriteLine(ans % MOD);
        }

        private static long recur(int n)
        {
            if (n == 1)
                return 1;
            long ans = 0;
            ans += ((recur(n - 1) % MOD) * 3) % MOD;
            return ans;
        }

        static int s_index = 0;
        static string[] s_tokens;
        private static string Next()
        {
            while (s_tokens == null || s_index == s_tokens.Length)
            {
                s_tokens = Console.ReadLine().Split(' ').ToArray();
                s_index = 0;
            }
            return s_tokens[s_index++];
        }

        private static int NextInt()
        {
            return Int32.Parse(Next());
        }

        private static long NextLong()
        {
            return Int64.Parse(Next());
        }
    }
}


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

namespace pro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            char[] splitChars = {'.', '!', '?'};
            string[] sentence = s.Split(splitChars);

            int k = sentence.Length;

            bool possible = true;
            int[] len = new int[k];
            for (int i = 0; i < k; i++)
            {
                sentence[i] = sentence[i].Trim();
                len[i] = sentence[i].Length;
                if (len[i] > 0) len[i] = len[i] + 1;
                if (len[i] > n)
                {
                    possible = false;
                    Console.WriteLine("Impossible");
                    return;
                }
            }

            if (possible)
            {
                   int count = 1;
                  int smsLength = 0;
                  for (int i = 0; i < k; i++)
                 {if(len[i] > 0)
                    {
                    if (smsLength + len[i] + 1 > n)
                   {
                       count++;
                      smsLength = len[i];
                   }
                  else
                  {
                      smsLength = smsLength + len[i] + 1;
                  }

                 }
                }

                Console.WriteLine(count);
            }
        }
    }
}


using System;

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine()) - 1;
        var r = n == -1 ? 0 : 1;

        for (var i = 0; i < n; i++)
            r = (r * 3) % 1000003;

        Console.WriteLine(r);
    }
}


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

namespace pro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ans = power3(n - 1) % 1000003;
            Console.WriteLine(ans);
        }

        public static int power3(int n)
        {
            var result = 1;
            for (var i = 0; i < n; i++)
                result = result * 3;

            return result;
        }
    }
}


using System;

namespace Codeforces_64
{
    class TaskA
    {
        static void Main()
        {
            int number = Int32.Parse(Console.ReadLine());

            if(number == 0)
                Console.WriteLine("0");

            int ret = 1;

            for (int i = 0; i < number - 1; i++)
            {
                ret *= 3;
            }

            Console.WriteLine((ret % 1000003).ToString());
        }
    }
}


using System;

namespace Codeforces_64
{
    class TaskA
    {
        static void Main()
        {
            int number = Int32.Parse(Console.ReadLine());

            int ret = 1;

            for (int i = 0; i < number - 1; i++)
            {
                ret *= 3;
            }

            Console.WriteLine((ret % 1000003).ToString());
        }
    }
}


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

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int mod = 1000003;
            int[] res = new int[1001];
            res[0] = 0;
            res[1] = 1;
            res[2] = 3;
            for (int i = 3; i < 1001; ++i)
            {
                res[i] = res[i - 1] * 3 % mod;
            }
            Console.WriteLine(res[n]);
        }
    }
}


using System;
class Test {
    static void Main(){
        int k = Int32.Parse(Console.ReadLine());
        double ans = cal(k);
        Console.WriteLine(ans);
    }
    static double cal(double n){
        if(n<=1){
            return 1;
        }else{
            return ((3*cal(n-1))%(1000000+3));
        }
    }
}


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

namespace ACming
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int o = 1;

            for (int i = 2; i <= n; i++)
                o = o * 3 % 1000003;

            Console.WriteLine(o);

        }
    }
}


using System;

namespace Codeforces_063_A
{
    class Program
    {
        static void Main()
        {
            string s;
            s = Console.ReadLine();
            int n = int.Parse(s);

            n--;
            int ans=1;
            for (int i = 0; i < n; i++)
            {
                ans *= 3;
                if (ans>1000003)
                    ans = ans % 1000003;
            }
            Console.WriteLine(ans);
  //          Console.ReadKey();
        }
    }
}


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

namespace CF_070A {
    class Program {
        static void Main(string[] args) {
            int n=int.Parse(Console.ReadLine());
            int o=1;
            for(int i=2;i<=n;i++) o=(o*3)%1000003;
            Console.WriteLine(o);
        }
    }
}


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

namespace pro
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ans = power3(n - 1);
            Console.WriteLine(ans);
        }

        public static int power3(int n)
        {
            var result = 1;
            for (var i = 0; i < n; i++)
                result = result * 3 % 1000003;

            return result;
        }
    }
}


//

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

namespace sar_cs
{
    public class Program
    {
        public class Parser
        {
            const int BufSize = 25000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new InvalidDataException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                checked
                {
                    while (c >= 0 && !char.IsWhiteSpace((char)c))
                    {
                        if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                        len++;
                        res = res * 10 - c;
                        c = Read();
                    }
                    if (len == 0) throw new InvalidDataException();
                    Back();
                    return res * sign;
                }
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-')
                {
                    sign = -1;
                    c = Read();
                }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c);
                    c = Read();
                }

                Back();
                double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c);
                    c = Read();
                }
                if (c == 13)
                {
                    c = Read();
                    if (c != 10) Back();
                }
                return sb.ToString();
            }

            public bool EOF
            {
                get
                {
                    if (Read() == -1) return true;
                    Back();
                    return false;
                }
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }
        }

        static void pe()
        {
            Console.WriteLine("???");
            Environment.Exit(0);
        }

        static void re()
        {
            Environment.Exit(55);
        }

        static int nosol()
        {
            Console.WriteLine("ERROR");
            return 0;
        }

        static Stopwatch sw = Stopwatch.StartNew();

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(52345235);

        static void Swap<T>(ref T a, ref T b)
        {
            T t = a;
            a = b;
            b = t;
        }

        static int Main(string[] args)
        {
            //Console.SetIn(File.OpenText("_input"));
            Parser parser = new Parser();
            while (!parser.SeekEOF)
            {
               int n = parser.ReadInt();
                int res = 1;
                if (n > 0)
                {
                    for (int i = 0; i < n-1; i++)
                        res = (res * 3) % 1000003;
                }

                Console.WriteLine(res);
            }

            return 0;
        }
    }
}


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

namespace prog_coder_26_03_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 0)
            {
                Console.WriteLine("1");
                return;
            }
            if (n == 1)
            {
                Console.WriteLine("1");
                return;
            }
            --n;
            int a = 1;
            for (int i = 0; i < n; ++i)
            {
                a *= 3;
                a %= 1000003;
            }
            Console.WriteLine(a);
        }
    }
}


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

namespace CodeForces
{
    class Prob70A
    {
        //Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square
        //k × k in size, divided into blocks 1 × 1 in size and paint there the main diagonal together with cells, which
        //lie above it, then the painted area will be equal to the area occupied by one cookie k in size. Fangy also has
        //a box with a square base 2^n × 2^n, divided into blocks 1 × 1 in size. In a box the cookies should not overlap,
        //and they should not be turned over or rotated.

        //To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest
        //cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the
        //repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size
        //1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the
        //end.

        int n; //dimensions of the box

        public Prob70A(int nn)
        {
            n = nn;
        }

        public int solve()
        {
            if (n < 2)
            {
                return 1;
            }
            return modularPow(3, n - 1, 1000003);
        }

        private static int modularPow(int b, int exp, int mod)
        {
            int c = 1;
            for (int i = 0; i < exp; ++i)
            {
                c = (c * b) % mod;
            }
            return c;
        }

        public override String ToString()
        {
            return "";
        }

        static void Main(string[] args)
        {
            int nn = Convert.ToInt32(Console.ReadLine());
            Prob70A prob = new Prob70A(nn);
            Console.WriteLine(prob.solve());
        }
    }
}


using System;

class P {
  static void Main() {
    var n = int.Parse(Console.ReadLine()) - 1;
    var res = 1;
    while (n --> 0) res = (res * 3) % 1000003;
    Console.Write(res);
  }
}


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

namespace Cookies
{
    internal class Program
    {
        private const int mod = 1000003;
        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 long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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

            if (n == 0)
                writer.WriteLine("1");
            else
            {
                writer.WriteLine(Pow(3, n - 1));
            }

            writer.Flush();
        }

        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 A
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine()) - 1;
        var r = 1;

        for (var i = 0; i < n; i++)
            r = (r * 3) % 1000003;

        Console.Write(r);
    }
}


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

namespace Learning
{
    class Program
    {
        static bool s_multiTest = false;
        static void Main(string[] args)
        {
            var o = Console.Out;
            var nTest = 1;
            if (s_multiTest)
            {
                nTest = NextInt();
            }

            for (int testId = 1; testId <= nTest; testId++)
            {
                Solve(testId, o);
            }
            Console.ReadLine();
        }
        static int MOD = (int)1e6 + 3;
        private static void Solve(int testId, TextWriter o)
        {
            var n = NextInt();
            long ans = recur(n);
            o.WriteLine(ans % MOD);
        }

        private static long recur(int n)
        {
            if (n == 1 || n == 0)
                return 1;
            long ans = 0;
            ans += ((recur(n - 1) % MOD) * 3) % MOD;
            return ans;
        }

        static int s_index = 0;
        static string[] s_tokens;
        private static string Next()
        {
            while (s_tokens == null || s_index == s_tokens.Length)
            {
                s_tokens = Console.ReadLine().Split(' ').ToArray();
                s_index = 0;
            }
            return s_tokens[s_index++];
        }

        private static int NextInt()
        {
            return Int32.Parse(Next());
        }

        private static long NextLong()
        {
            return Int64.Parse(Next());
        }
    }
}


using System;
namespace Iran
{
    class Amir
    {
        public static void Main()
        {
            int n=Convert.ToInt32(Console.ReadLine());
            if(n==0)
            {
                Console.WriteLine("1");
            }
            else
            {
                int ans=1;
                for(int i=1;i<n;++i)
                {
                    ans*=3;
                    ans%=(1000000+3);
                }
                Console.WriteLine(ans);
            }
        }
    }
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            long res = 1;
            for (int i = 1; i < n; i++)
            {
                res *= 3;
                res = res % (1000000 + 3);
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}


using System;

namespace Codeforces_64
{
    class TaskA
    {
        static void Main()
        {
            int number = Int32.Parse(Console.ReadLine());

            int ret = 1;

            for (int i = 0; i < number - 1; i++)
            {
                ret *= 3;
                ret %= 1000003;
            }

            Console.WriteLine((ret % 1000003).ToString());
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
         int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));

            long ans = CNK(n - 1, A[0]);

            int m = n - A[0];
            for (int i = 1; i < 10; i++) {
                ans *= CNK(m, A[i]);
                m -= A[i];
            }

            for (int i = 0; i < m; i++) {
                ans *= 9;
            }

            Console.WriteLine(ans);
	 }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        // Mono lacks this override of string.Join()
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = 1;
                    c = Read();
                }
                int len = 0;

                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

            public int[] ReadIntArr(int n)
            {
                var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;
            }

            public long[] ReadLongArr(int n)
            {
                var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;
            }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { Environment.Exit(55); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(5);

        #endregion Helpers

        static int[] minQ;

        const int M = 1000000007;

        static int C(int n, int k)
        {
            return sar_cs_structs.Combinations.Count(n + k - 1, k) % M;
        }

        static long f(int n, int d)
        {
            checked
            {
                //if (d == 10) return n == 0 ? 1 : 0;
                if (n < minQ[d]) return 0;
                //if (n == 0) return 0;

                if (n == 0 || d > 9) throw new Exception();

                long result = 0;
                for (int i = minQ[d]; i <= n; i++)
                {
                    long t1;

                    if (i == 0)
                    {
                        if (d == 9) t1 = n == 0 ? 1 : 0;
                        else t1 = f(n, d + 1);
                    }
                    else if (i == n)
                    {
                        if (minQ.Skip(d + 1).Any(q => q > 0)) t1 = 0;
                        else if (d == 0 && i > 1) t1 = 0;
                        else t1 = 1;
                    }
                    else
                    {
                        if (d == 9)
                            t1 = 0;
                        else
                        {
                            t1 = f(n - i, d + 1);
                            long t2 = d == 0 ? C(n - i, i) : C(n - i + 1, i);
                            //t2 /= sar_cs_structs.Permutations.Factorial(i);
                            t1 *= t2;
                        }
                    }

                    t1 %= M;
                    result = (result + t1) % M;
                }

                return result;
            }
        }

        static void Main(string[] args)
        {
            checked
            {
                //Console.SetIn(File.OpenText("_input"));
                var parser = new Parser();
                while (!parser.SeekEOF)
                {
                    int n = parser.ReadInt();
                    minQ = parser.ReadIntArr(10);

                    //for (int i = 100; i <= 999; i++) if (i.ToString().Contains('0') && i.ToString().Contains('1')) Console.WriteLine(i);
                    //Console.WriteLine("");
                    //Console.Write(f(3, 0));

                    for (int d = 0; d <= 9; d++)
                    {
                        Console.Write("d=" + d + ": ");
                        for (int i = 1; i <= n; i++)
                            Console.Write(f(i, d) + " ");
                        Console.WriteLine();
                    }

                    Console.WriteLine(f(n, 0));
                }
            }
        }

        //static void Main(string[] args)
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        // Mono lacks this override of string.Join()
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = 1;
                    c = Read();
                }
                int len = 0;

                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

            public int[] ReadIntArr(int n)
            {
                var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;
            }

            public long[] ReadLongArr(int n)
            {
                var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;
            }
        }

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { Environment.Exit(55); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(5);

        #endregion Helpers

        static int[] minQ;

        const int M = 1000000007;

        static int[,] C = GetCountModTable(100, 100, M);

        static public int[,] GetCountModTable(int maxN, int maxK, int Mod)
        {
            if (maxN < 0 || maxK < 0) throw new ArgumentException();
            if (Mod > int.MaxValue / 2) throw new ArgumentOutOfRangeException();
            var result = new int[maxN + 1, maxK + 1];
            for (int n = 0; n <= maxN; n++)
                for (int k = 0; k <= maxK; k++)
                    if (k == 0) result[n, k] = 1;
                    else if (n == 0) result[n, k] = 0;
                    else result[n, k] = (result[n - 1, k] + result[n, k - 1]) % Mod;
            return result;
        }

        static int[,] fcache;

        static long f(int n, int d)
        {
            checked
            {
                //if (d == 10) return n == 0 ? 1 : 0;
                if (n < minQ[d]) return 0;
                //if (n == 0) return 0;

                if (n == 0 || d > 9) throw new Exception();

                if (fcache[n, d] != 0) return fcache[n, d] - 1;

                long result = 0;
                for (int i = minQ[d]; i <= n; i++)
                {
                    long t1;

                    if (i == 0)
                    {
                        if (d == 9) t1 = n == 0 ? 1 : 0;
                        else t1 = f(n, d + 1);
                    }
                    else if (i == n)
                    {
                        if (minQ.Skip(d + 1).Any(q => q > 0)) t1 = 0;
                        else if (d == 0 && i > 1) t1 = 0;
                        else t1 = 1;
                    }
                    else
                    {
                        if (d == 9)
                            t1 = 0;
                        else
                        {
                            t1 = f(n - i, d + 1);
                            var t2 = d == 0 ? C[n - i, i] : C[n - i + 1, i];
                            t1 *= t2;
                        }
                    }

                    t1 %= M;
                    result = (result + t1) % M;
                }

                fcache[n, d] = (int)result + 1;
                return result;
            }
        }

        static void Main(string[] args)
        {
            checked
            {
                //Console.SetIn(File.OpenText("_input"));
                var parser = new Parser();
                while (!parser.SeekEOF)
                {
                    int n = parser.ReadInt();
                    minQ = parser.ReadIntArr(10);

                    //for (int i = 100; i <= 999; i++) if (i.ToString().Contains('0') && i.ToString().Contains('1')) Console.WriteLine(i);
                    //Console.WriteLine("");

                    //Console.WriteLine(f(3, 0));

                    //for (int d = 0; d <= 9; d++)
                    //{
                    //    Console.Write("d=" + d + ": ");
                    //    for (int i = 1; i <= n; i++)
                    //        Console.Write(f(i, d) + " ");
                    //    Console.WriteLine();
                    //}

                    fcache = new int[101, 10];
                    long result = 0;
                    for (int i = 1; i <= n; i++)
                        result = (result + f(i, 0)) % M;

                    if (minQ[0] <= 1 && minQ.Skip(1).All(q => q == 0)) result--;

                    Console.WriteLine(result);
                }
            }
        }

        //static void Main(string[] args)
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
           const int MOD = 1000000007;
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));

            long ans = 0;
            for (int k = a.Sum(); k <= n; k++) {

                long[,] dp = new long[110, 30];
                dp[k, 0] = 1;

                for (int j = 0; j < 10; j++)
                    for (int i = a[j]; i <= k; i++)
                        for (int l = a[j]; l <= i; l++) {
                            if (j == 0) dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i - 1, l) % MOD) % MOD;
                            else dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i, l) % MOD) % MOD;
                        }

                ans += dp[0, 10];
                ans %= MOD;
            }

            Console.WriteLine(ans);
	 }
     static long CNK(long n, long k) {
            if (k == 0) return 1;
            if (n < k) return 0;
            if (n == k) return 1;
            return (n * CNK(n - 1, k - 1)) / k;
        }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
          int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));

            long ans = CNK(n - 1, A[0]);

            int m = n - A[0];
            for (int i = 1; i < 10; i++) {
                ans *= CNK(m, A[i]);
                m -= A[i];
                ans %= 1000000007;
            }

            for (int i = 0; i < m; i++) {
                ans *= 9;
                ans %= 1000000007;
            }

            Console.WriteLine(ans);
	 }
     static long CNK(long n, long k) {
            if (k == 0) return 1;
            if (n < k) return 0;
            if (n == k) return 1;
            return (n * CNK(n - 1, k - 1)) / k;
        }
}


using System;
using System.Linq;

public static class Program
{

    public static void Main()
    {
         var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
         var n = nn[0];
         var k = nn[1];
         string s =  Console.ReadLine();
         bool[,] dp = new bool[105,105];
         for(int i = 0;i < 105;i++)
            for(int j = 0;j < 105;j++)
               dp[i,j] = false;
         dp[0,0] = true;
         int mx = 0,mn = 0;
         int sz = 0;
         bool ans = false;
         for(int i = 0;i < n;i++)
            if(s[i] == 'N')
               sz++;
            else
            {
               if(sz > mn)
                   mn = sz;
               sz = 0;
            }
         if(sz > mn)
            mn = sz;
         if(mn > k)
         {
            Console.WriteLine("NO");
            return;
         }
         for(int i = 1;i <= n;i++)
         {
            if(s[i - 1] == 'Y')
               dp[i,0] = true;
            if(s[i - 1] == 'N' || s[i - 1] == '?')
            {
               for(int j = 1;j <= i;j++)
                  if(dp[i - 1,j - 1])
                     dp[i,j] = true;
            }

            if(dp[i,k])
            {
               Console.WriteLine("YES");
               return;
            }
         }
         Console.WriteLine("NO");

    }
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var k = nn[1];
        var n = nn[0];
        string str;
        str = Console.ReadLine();
        var cur1 = 0;
        var cur2 = 0;
        var mx1 = 0;
        var mx2 = 0;
        for (var i = 0; i < n; i++) {
            if (str[i] == 'Y') {
                cur1 = 0;
                cur2 = 0;
            }
            else if (str[i] == 'N') {
                cur1++;
                cur2++;
            }
            else {
                cur1 = 0;
                cur2++;
            }
            if (cur1 > mx1) {
                mx1 = cur1;
            }
            if (cur2 > mx2) {
                mx2 = cur2;
            }
        }
        if (mx1 <= k && k <= mx2) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }

}


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

namespace sharp_ACM
{

    class Program
    {
        public static int[] ReadInts()
        {
            return Console
                .ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();
        }

        public static int ReadInt()
        {
            return ReadInts().Single();
        }

        public static string[] ReadStrings()
        {
            return Console
                .ReadLine()
                .Split();
        }

        static long GetLong(string a)
        {
            if (!a.Contains("."))
                return long.Parse(a) * 100;
            if (a[a.Length - 2] == '.')
                return long.Parse(a.Replace(".", "")) * 10;
            return long.Parse(a.Replace(".", ""));
        }

        static void Main(string[] args)
        {
            int n, k;
            var nkstr = ReadInts();
            n = nkstr[0];
            k = nkstr[1];
            var line = Console.ReadLine();
            HashSet<int> totalPossible = new HashSet<int>();
            totalPossible.Add(0);
            HashSet<int> possibleLens;
            possibleLens = new HashSet<int>();
            possibleLens.Add(0);
            var definitely = 0;
            int cur = 0;
            for (int i = 0; i < n; ++i)
            {
                if (line[i] == 'N')
                    cur++;
                else
                    cur = 0;
                definitely = Math.Max(definitely, cur);
            }
            if (k < definitely)
            {
                Console.WriteLine("NO");
                return;
            }
            for (int i = 0; i < n; ++i)
            {
                var newPossible = new HashSet<int>();
                if (line[i] == 'Y')
                {
                    possibleLens.Clear();
                    possibleLens.Add(0);
                }
                else if (line[i] == 'N')
                {
                    foreach (var pos in possibleLens)
                    {
                        newPossible.Add(pos + 1);
                    }
                    possibleLens = newPossible;
                }
                else if (line[i] == '?')
                {
                    foreach (var pos in possibleLens)
                        newPossible.Add(pos + 1);
                    newPossible.Add(0);
                    possibleLens = newPossible;
                }
                foreach (var pos in possibleLens)
                    totalPossible.Add(pos);
            }
            if (totalPossible.Contains(k))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}
/*

*/


using System;
using System.Linq;

public static class Program
{

    public static void Main()
    {
         var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
         var n = nn[0];
         var k = nn[1];
         string s =  Console.ReadLine();
         bool[,] dp = new bool[105,105];
         for(int i = 0;i < 105;i++)
            for(int j = 0;j < 105;j++)
               dp[i,j] = false;
         dp[0,0] = true;
         int mx = 0,mn = 0;
         int sz = 0;
         bool ans = false;
         for(int i = 0;i < n;i++)
            if(s[i] == 'N')
               sz++;
            else
            {
               if(sz > mn)
                   mn = sz;
               sz = 0;
            }
         if(sz > mn)
            mn = sz;
         if(mn > k)
         {
            Console.WriteLine("NO");
            return;
         }
         for(int i = 1;i < n;i++)
         {
            if(s[i - 1] == 'Y')
               dp[i,0] = true;
            if(s[i - 1] == 'N' || s[i - 1] == '?')
            {
               for(int j = 1;j <= i;j++)
                  if(dp[i - 1,j - 1])
                     dp[i,j] = true;
            }

            if(dp[i,k])
            {
               Console.WriteLine("YES");
               return;
            }
         }
         Console.WriteLine("NO");

    }
}


using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string text = Console.ReadLine();
        string[] nums = text.Split(' ');

        int n = Convert.ToInt32(nums[0]);
        int k = Convert.ToInt32(nums[1]);
        string str = Console.ReadLine();
        str = "Y"+str+"Y";
        int max = 0;
        int cur = 0;

        for (int i = 1; i < n+1; i++)
        {
            if( str[i] == 'N')
            {
                cur++;
            }
            else //if(str[i] == 'Y'|'?')
            {
                cur=0;
            }

            if(cur > max) max=cur;
        }
        bool find = false;
        //Console.WriteLine(k);
        //Console.WriteLine(str);
        if(k>=max)
        {
            for (int i = k+1; i < n+2; i++)
            {
                if((str[i]=='?' || str[i]=='Y') && (str[i-k-1]=='?' || str[i-k-1]=='Y'))
                {
                    //Console.WriteLine(i);
                    find = true;
                    for(int j=1;j<k+1;j++)
                    {
                        if(str[i-j]=='Y') find = false;
                    }
                }
            }
        }

        if(find) Console.WriteLine("YES");
        else Console.WriteLine("NO");

    }

}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var k = nn[1];
        var n = nn[0];
        string str;
        str = Console.ReadLine();
        var cur1 = 0;
        var cur2 = 0;
        var mx1 = 0;
        var mx2 = 0;
        for (var i = 0; i < n; i++) {
            if (str[i] == 'Y') {
                cur1 = 0;
                cur2 = 0;
            }
            else if (str[i] == 'N') {
                cur1++;
                cur2++;
            }
            else {
                cur1 = 0;
                cur2++;
            }
            if (cur1 > mx1) {
                mx1 = cur1;
            }
            if (cur2 > mx2) {
                mx2 = cur2;
            }
        }
        cur2 = 0;
        if (mx1 > k) {
            mx2 = 0;
        }
        for (var i = 0; i <= n - k; i++) {
            cur1 = 1;
            if ((i == 0 || (i > 0 && str[i - 1] != 'N')) && (i + k == n || (i + k < n && str[i + k] != 'N'))) {
                for (var j = 0; j < k; j++) {
                    if (str[i + j] == 'Y') {
                        cur1 = 0;
                    }
                }
                if (cur1 == 1) {
                    cur2 = 1;
                }
            }
        }
        if (mx2 == 0) {
            Console.WriteLine("NO");
        }
        else if (cur2 == 1) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }

}


using System;
using System.Linq;

public static class Program
{
    public static void Main()
    {
        var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = tmp[0];
        var k = tmp[1];
        var s = Console.ReadLine();
        var max_n = 0;
        var cur_n = 0;
        for (var i = 0; i < n; ++i) {
            if (s[i] == 'N') {
                cur_n++;
                if (cur_n > max_n) {
                    max_n = cur_n;
                }
            } else {
                cur_n = 0;
            }
        }
        if (max_n > k) {
            Console.WriteLine("NO");
            return;
        }
        var p = -1;
        var ans = false;
        for (var i = 0; i <= n; ++i) {
            if (i < n && (s[i] == 'N' || s[i] == '?')) {
                if (p == -1) {
                    p = i;
                }
            } else if (p != -1) {
                for (int j = p; j + k <= i; ++j) {
                    if ((j - 1 < 0 || s[j - 1] != 'N') && (j + k >= n || s[j + k] != 'N')) {
                        ans = true;
                    }
                }
                p = -1;
            }
        }
        if (ans) {
            Console.WriteLine("YES");
        } else {
            Console.WriteLine("NO");
        }
    }
}


using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string text = Console.ReadLine();
        string[] nums = text.Split(' ');

        int n = Convert.ToInt32(nums[0]);
        int k = Convert.ToInt32(nums[1]);
        string str = Console.ReadLine();
        str = "Y"+str+"Y";
        int max = 0;
        int cur = 0;

        for (int i = 1; i < n+1; i++)
        {
            if( str[i] == 'N')
            {
                cur++;
            }
            else //if(str[i] == 'Y'|'?')
            {
                cur=0;
            }

            if(cur > max) max=cur;
        }
        bool find = false;
        //Console.WriteLine(k);
        //Console.WriteLine(str);
        if(k>=max)
        {
            for (int i = k+1; i < n+2; i++)
            {
                if((str[i]=='?' || str[i]=='Y') && (str[i-k-1]=='?' || str[i-k-1]=='Y'))
                {
                    //Console.WriteLine(i);
                    find = true;
                    for(int j=1;j<k+1;j++)
                    {
                        if(str[i-j]=='Y') find = false;
                    }
                }
                if(find)
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
        }

        Console.WriteLine("NO");

    }

}


using System;
using System.Linq;

public static class Program
{
    public static void Main()
    {
        var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = tmp[0];
        var k = tmp[1];
        var s = Console.ReadLine();
        var max_n = 0;
        var cur_n = 0;
        for (var i = 0; i < n; ++i) {
            if (s[i] == 'N') {
                cur_n++;
                if (cur_n > max_n) {
                    max_n = cur_n;
                }
            } else {
                cur_n = 0;
            }
        }
        if (max_n > k) {
            Console.WriteLine("NO");
            return;
        } else if (max_n == k) {
            Console.WriteLine("YES");
            return;
        }
        var p = -1;
        var ans = false;
        for (var i = 0; i <= n; ++i) {
            if (i < n && (s[i] == 'N' || s[i] == '?')) {
                if (p == -1) {
                    p = i;
                }
            } else if (p != -1) {
                for (int j = p; j + k <= i; ++j) {
                    if ((j - 1 < 0 || s[j - 1] != 'N') && (j + k >= n || s[j + k] != 'N')) {
                        ans = true;
                    }
                }
                p = -1;
            }
        }
        if (ans) {
            Console.WriteLine("YES");
        } else {
            Console.WriteLine("NO");
        }
    }
}


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

namespace sharp_ACM
{

    class Program
    {
        public static int[] ReadInts()
        {
            return Console
                .ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();
        }

        public static int ReadInt()
        {
            return ReadInts().Single();
        }

        public static string[] ReadStrings()
        {
            return Console
                .ReadLine()
                .Split();
        }

        static long GetLong(string a)
        {
            if (!a.Contains("."))
                return long.Parse(a) * 100;
            if (a[a.Length - 2] == '.')
                return long.Parse(a.Replace(".", "")) * 10;
            return long.Parse(a.Replace(".", ""));
        }

        static void Main(string[] args)
        {
            int n, k;
            var nkstr = ReadInts();
            n = nkstr[0];
            k = nkstr[1];
            var line = Console.ReadLine();
            var totalPossible = new HashSet<int>();
            totalPossible.Add(0);
            var possibleLens = new HashSet<int> {0};
            var definitely = 0;
            int cur = 0;
            for (int i = 0; i < n; ++i)
            {
                if (line[i] == 'N')
                    cur++;
                else
                    cur = 0;
                definitely = Math.Max(definitely, cur);
            }
            if (k < definitely)
            {
                Console.WriteLine("NO");
                return;
            }
            for (int i = 0; i < n; ++i)
            {
                var newPossible = new HashSet<int>();
                if (line[i] == 'Y')
                {
                    foreach (var pos in possibleLens)
                        totalPossible.Add(pos);
                    possibleLens.Clear();
                    possibleLens.Add(0);
                }
                else if (line[i] == 'N')
                {
                    foreach (var pos in possibleLens)
                    {
                        newPossible.Add(pos + 1);
                    }
                    possibleLens = newPossible;
                }
                else if (line[i] == '?')
                {
                    foreach (var pos in possibleLens)
                        totalPossible.Add(pos);
                    foreach (var pos in possibleLens)
                        newPossible.Add(pos + 1);
                    newPossible.Add(0);
                    possibleLens = newPossible;
                }
            }
            foreach (var pos in possibleLens)
                totalPossible.Add(pos);
            if (totalPossible.Contains(k))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}
/*
7 3
NN?NY??

*/


using System;

class Program
{
	static void Main(string[] args)
	{
	    var ss = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(ss[0]);
        var m = int.Parse(ss[1]);
        var GL = true;
        var HF = false;
		string s = Console.ReadLine();
		for (int i=0; i+m+1<=n; i++)
		{
		    var ok = false;
		    for (int j=0; j<=m; j++)
	            if (s[i+j] != 'N')
		            ok = true;
			if (!ok)
			    GL = false;
		}
		for (int i=0; i+m<=n; i++)
		{
		    var ok = true;
		    for (int j=0; j<m; j++)
		        if (s[i+j] == 'Y')
		            ok = false;
		    if (i != 0 && s[i-1] == 'N')
		        ok = false;
		    if (i+m != n && s[i+m] == 'N')
		        ok = false;
		    if (ok)
		        HF = true;
		}
		if (GL && HF)
		    Console.Write("YES\n");
		else
		    Console.Write("NO\n");
	}
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var k = nn[1];
        var n = nn[0];
        string str;
        str = Console.ReadLine();
        var cur1 = 0;
        var cur2 = 0;
        var mx1 = 0;
        var mx2 = 0;
        for (var i = 0; i < n; i++) {
            if (str[i] == 'Y') {
                cur1 = 0;
                cur2 = 0;
            }
            else if (str[i] == 'N') {
                cur1++;
                cur2++;
            }
            else {
                cur1 = 0;
                cur2++;
            }
            if (cur1 > mx1) {
                mx1 = cur1;
            }
            if (cur2 > mx2) {
                mx2 = cur2;
            }
        }
        cur2 = 0;
        mx2 = 1;
        if (mx1 > k) {
            mx2 = 0;
        }
        for (var i = 0; i <= n - k; i++) {
            cur1 = 1;
            if ((i == 0 || (i > 0 && str[i - 1] != 'N')) && (i + k == n || (i + k < n && str[i + k] != 'N'))) {
                for (var j = 0; j < k; j++) {
                    if (str[i + j] == 'Y') {
                        cur1 = 0;
                    }
                }
                if (cur1 == 1) {
                    cur2 = 1;
                }
            }
        }
        if (mx2 == 0) {
            Console.WriteLine("NO");
        }
        else if (cur2 == 1) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }

}


using System;
using System.Linq;

public static class Program
{

    public static void Main()
    {
         var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
         var n = nn[0];
         var k = nn[1];
         string s =  Console.ReadLine();
         bool[,] dp = new bool[105,105];
         for(int i = 0;i < 105;i++)
            for(int j = 0;j < 105;j++)
               dp[i,j] = false;
         dp[0,0] = true;
         int mx = 0,mn = 0;
         int sz = 0;
         bool ans = false;
         for(int i = 0;i < n;i++)
            if(s[i] == 'N')
               sz++;
            else
            {
               if(sz > mn)
                   mn = sz;
               sz = 0;
            }
         if(sz > mn)
            mn = sz;
         if(mn > k)
         {
            Console.WriteLine("NO");
            return;
         }
         for(int i = 1;i <= n;i++)
         {
            if(s[i - 1] == 'Y')
               dp[i,0] = true;
            if(s[i - 1] == 'N' || s[i - 1] == '?')
            {
               for(int j = 1;j <= i;j++)
                  if(dp[i - 1,j - 1])
                     dp[i,j] = true;
               if(s[i - 1] == '?')
                  dp[i,0] = true;
            }
            //Console.WriteLine(dp[i,k]);
            if(dp[i,k] && i == n)
            {
                  Console.WriteLine("YES");
                  return;
            }
            if(dp[i - 1,k] && (s[i - 1] == '?' || s[i - 1] == 'Y'))
            {
                  Console.WriteLine("YES");
                  return;
            }
         }
         Console.WriteLine("NO");

    }
}


using System;
using System.IO;

class SOS{
    static void Main(){
         string[] tmp = Console.ReadLine().Split();
         int n=int.Parse(tmp[0]);
         int k=int.Parse(tmp[1]);
         string S=Console.ReadLine();
         int ans=0;
         for(int i=0;i+k-1<n;i++){
             int ok=1;
             char[] s=S.ToCharArray();
             for(int j=i;j<=i+k-1;j++){
                 if(s[j]=='?')s[j]='N';
                 if(s[j]=='Y')ok=0;
             }
             if(ok==0)continue;
             for(int j=0;j<n;j++)
                 if(s[j]=='?')s[j]='Y';
             int cur=0,mx=0;
             for(int j=0;j<n;j++){
                 if(s[j]=='N'){
                     cur++;
                     if(cur>mx)mx=cur;
                 }else{
                     cur=0;
                 }
             }
             if(mx==k)
                ans=1;
         }
         if(ans==1)
            Console.WriteLine("YES");
            else

            Console.WriteLine("NO");
    }

}


using System;
using System.Linq;

public static class Program
{

public static void Main()
{
	var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
	int n = nn[0];
	int K = nn[1];
	string s = Console.ReadLine();
	bool[,,] dp = new bool[102, 102, 102];
	dp[0, 0, 0] = true;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k <= n; ++k)
			{
				if (!dp[i, j, k]) continue;
				if (s[i] != 'N') dp[i+1, j, 0] = true;
				if (s[i] != 'Y') dp[i+1, Math.Max(j, k+1), k+1] = true;
			}
	bool flag = false;
	for (int i = 0; i <= n; ++i) flag |= dp[n, K, i];
	Console.WriteLine(flag ? "YES" : "NO");
}

}


using System;
using System.Collections.Generic;

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

            long n = long.Parse(tokens[0]);
            long b = long.Parse(tokens[1]);

            var factors = new Dictionary<long, long>();

            for (long i = 2; i <= 1000000; i++)
            {
                long count = 0;

                while (b % i == 0)
                {
                    b /= i;
                    count++;
                }

                if (count > 0)
                {
                    factors.Add(i, count);
                }
            }

            if (b > 1)
            {
                factors.Add(b, 1);
            }

            long result = long.MaxValue;

            foreach (var f in factors)
            {
                long x = n;
                long count = 0;

                while (x >= f.Key)
                {
                    x /= f.Key;
                    count += x;
                }

                result = Math.Min(result, count / f.Value);
            }

            Console.WriteLine(result);
        }
    }
}


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

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

    void solve()
    {
        var N = cin.nextlong;
        var B = cin.nextlong;

        var H = new Map<long, int>();
        var T = B;
        for (long i = 2; i <= T / i; i++)
        {
            while (T % i == 0)
            {
                T /= i;
                H[i]++;
            }
        }
        if (T != 1)
        {
            H[T]++;
        }
        //var G = new Map<long, int>();
        //T = N;
        //for (long i = 2; i * i <= T; i++)
        //{
        //    while (T % i == 0)
        //    {
        //        T /= i;
        //        G[i]++;
        //    }
        //}
        //if (T != 1)
        //{
        //    G[T]++;
        //}

        long ans = long.MaxValue;
        //foreach (var v in H)
        //{
        //    var P = 0L;
        //    if(G.ContainsKey(v.Key))
        //    {
        //        P = G[v.Key];
        //        WriteLine(v.Key + " " + P);
        //    }
        //    chmin(ref ans, P / v.Value);
        //}

        foreach (var v in H)
        {
            var key = v.Key;
            var P = N / key;

            while (N / key >= v.Key)
            {
                key *= v.Key;
                P += N / key;
            }
            var value = v.Value;

            var c = P / value;

            //WriteLine(P + " " + value);
            chmin(ref ans, c);
        }
        WriteLine(ans);
    }

}

class Map<TKey, TValue> : Dictionary<TKey, TValue>
{
    public new TValue this[TKey key]
    {
        get
        {
            if (!ContainsKey(key))
            {
                base[key] = default(TValue);
            }
            return base[key];
        }
        set
        {
            base[key] = value;
        }
    }
}
static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

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

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

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


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        long[] nb = Console.ReadLine().Split().Select(long.Parse).ToArray();
        //えっと、つまり素因数分解して約数の数を数えればOK
        var factors = Factors(nb[1]);
        long res = long.MaxValue;
        foreach (var factor in factors.GroupBy(x => x))
        {
            long current = factor.Key;
            long count = 0;
            double limit = Sqrt(nb[0] + 100);
            while (nb[0] >= current)
            {
                count += nb[0] / current;
                if (((double)current * (double)factor.Key) >= nb[0] + 114514) break;
                current *= factor.Key;
            }
            res = Min(res, count / factor.Count());
        }
        Console.WriteLine(res);
    }

    static long[] Factors(long n)
    {
        List<long> res = new List<long>();
        while (n % 2 == 0)
        {
            res.Add(2);
            n /= 2;
        }
        long i = 3;
        double ub = Sqrt(n);
        while (i <= ub + 1)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i += 2;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}