using System;

namespace Problem51Nod
{
    class Program
    {
        public static void Main(String[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(input[0]);
            long sum = Convert.ToInt64(input[1]);
            input = Console.ReadLine().Split(' ');
            long[] nums = new long[n];

            for (int i = 0; i < n; i++)
                nums[i] = Convert.ToInt64(input[i]);

            Init(nums);
            Console.WriteLine(Cal(Nums.Length - 1, sum));
        }

        static long Mod = 1000000007;
        static long[] Nums, InvFacts;

        static void Init(long[] nums)
        {
            long[] invs = new long[30];
            InvFacts = new long[30];
            invs[1] = InvFacts[1] = 1;

            for (int i = 2; i < invs.Length; i++)
            {
                invs[i] = (Mod - Mod / i * invs[Mod % i] % Mod) % Mod;
                InvFacts[i] = InvFacts[i - 1] * invs[i] % Mod;
            }

            Nums = new long[nums.Length];

            for (int i = 0; i < nums.Length; i++)
                Nums[i] = nums[i] + 1;

            Array.Sort(Nums, (a, b) => b.CompareTo(a));
        }

        static long Cal(int index, long sum)
        {
            int k = Nums.Length - 1;
            long result = Cmn(sum + k, k);

            for(int i = index; i >= 0 && Nums[i] <= sum; i--)
                result -= Cal(i - 1, sum - Nums[i]);

            return result;
        }

        static long Cmn(long m, long n)
        {
            long result = 1;

            for(long i = m - n + 1; i <= m; i++)
                result = i % Mod * result % Mod;

            result = result * InvFacts[n] % Mod;
            return result;
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const int Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            if (ret >= Mod)
                ret -= Mod;
            if(ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Solution = Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const int Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            if (ret >= Mod)
                ret -= Mod;
            if (ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const Int64 Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            while(ret >= Mod)
                ret -= Mod;
            while(ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


using System;
using System.IO;
using System.Linq;

namespace Codeforces.R258
{
    public class Task_E
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_E().Solve();
        }

        private long[] f;
        private int n;
        private const long MOD = (long)(1e9 + 7);

        private void Solve()
        {
            var parts = Console.ReadLine().Split().Select(long.Parse).ToArray();
            n = (int)parts[0];
            long s = parts[1];
            f = Console.ReadLine().Split().Select(long.Parse).ToArray();
            for (int i = 0; i < f.Length; i++)
            {
                f[i]++;
            }

            var ans = (go(0, s) + MOD) % MOD;
            Console.WriteLine(ans);
        }

        private long go(int pos, long s)
        {
            if (s < 0)
                return 0;

            long result = 0;
            if (pos == n)
            {
                result = C(s + n - 1, n - 1);
            }
            else
            {
                result = go(pos + 1, s) - go(pos + 1, s - f[pos]);
            }

//            Console.WriteLine("go({0},{1}) = {2}", pos, s, result);
            return result;
        }

        private long C(long n, long k)
        {
            long result = 1;
            for (long i = 2; i <= k; i++)
                result = (result * inv(i)) % MOD;

            for (long i = n - k + 1; i <= n; i++)
                result = (result * (i % MOD)) % MOD;

//            Console.WriteLine("C({0}, {1}) = {2}", n, k, result);
            return result;
        }

        private static void ExEuclidean(long a, long b, out long x, out long y)
        {
            if (a == 1)
            {
                x = 1;
                y = 0;
            }
            else
            {
                long x1, y1;
                ExEuclidean(b % a, a, out x1, out y1);
                x = y1 - (b / a) * x1;
                y = x1;
            }
        }

        private static long inv(long a)
        {
            long x, y;
            ExEuclidean(a, MOD, out x, out y);
            return (x + MOD) % MOD;
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const int Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            if (ret >= Mod)
                ret -= Mod;
            if (ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const int Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            if (ret >= Mod)
                ret -= Mod;
            if (ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


using System;
using System.IO;
using System.Linq;

namespace Codeforces.R258
{
    public class Task_E
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_E().Solve();
        }

        private long[] f;
        private int n;
        private const long MOD = (long)(1e9 + 7);

        private void Solve()
        {
            var parts = Console.ReadLine().Split().Select(long.Parse).ToArray();
            n = (int)parts[0];
            long s = parts[1];
            f = Console.ReadLine().Split().Select(long.Parse).ToArray();
            for (int i = 0; i < f.Length; i++)
            {
                f[i]++;
            }

            var ans = (go(0, s) + MOD) % MOD;
            Console.WriteLine(ans);
        }

        private long go(int pos, long s)
        {
            if (s < 0)
                return 0;

            long result = 0;
            if (pos == n)
            {
                result = C(s + n - 1, n - 1);
            }
            else
            {
                result = go(pos + 1, s) - go(pos + 1, s - f[pos]);
            }

            //            Console.WriteLine("go({0},{1}) = {2}", pos, s, result);
            return result;
        }

        private long C(long n, long k)
        {
            long result = 1;
            for (long i = 2; i <= k; i++)
                result = (result * inv(i) % MOD) % MOD;

            for (long i = n - k + 1; i <= n; i++)
                result = (result * (i % MOD)) % MOD;

            //            Console.WriteLine("C({0}, {1}) = {2}", n, k, result);
            return result;
        }

        private static void ExEuclidean(long a, long b, out long x, out long y)
        {
            if (a == 1)
            {
                x = 1;
                y = 0;
            }
            else
            {
                long x1, y1;
                ExEuclidean(b % a, a, out x1, out y1);
                x = y1 - (b / a) * x1;
                y = x1;
            }
        }

        private static long inv(long a)
        {
            long x, y;
            ExEuclidean(a, MOD, out x, out y);
            return (x + MOD) % MOD;
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const Int64 Mod = (Int64)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            while(ret >= Mod)
                ret -= Mod;
            while(ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Solution = Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var h = sc.Integer();
            var n = sc.Long();
            long l = 1;
            long r = 1L << h;
            long count = 0;
            var goL = true;
            for (int i = 0; i < h; i++)
            {
                var m = (l + r) >> 1;
                //Debug.WriteLine(m);
                count++;
                if (n <= m)
                {
                    if (!goL)
                    {
                        count += (1L << (h - i)) - 1;
                    }
                    goL = false;
                    r = m - 1;
                }
                else
                {
                    if (goL)
                    {
                        count += (1L << (h - i)) - 1;
                    }
                    goL = true;
                    l = m + 1;
                }
            }
            IO.Printer.Out.WriteLine(count);

        }

        internal IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; }
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }

    }

}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Linq;
    public class Printer : StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
        }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
        public void Flush() { str.Flush(); }

    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion


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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public Int64 ReadNextInt64()
        {
            return Int64.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            return double.Parse(ReadNextToken());
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        Int64 [,] count;
        bool[,] wayOut;

        int h;
        Int64 exit;

        public void Solve()
        {
            h = ioHelper.ReadNextInt();
            exit = ioHelper.ReadNextInt64();

            count = new Int64[h + 1, 2];
            wayOut = new bool[h + 1, 2];

            int curH=0, wayIn;

            for(wayIn = 0; wayIn< 2; wayIn++)
            {
                count[curH,wayIn] = 1;
                wayOut[curH, wayIn] = wayIn != 1;
            }

            for (curH = 1; curH <= h; curH++)
            {
                for (wayIn = 0; wayIn < 2; wayIn++)
                {
                    count[curH, wayIn] = 0;
                    bool wOut = wayOut[curH - 1, 1 - wayIn];
                    count[curH, wayIn] += count[curH - 1, 1 - wayIn];
                    int wwOut = wOut ? 1 : 0;
                    if (wwOut == wayIn)
                        wwOut = 1 - wwOut;
                    bool wOut2 = wayOut[curH - 1, 1 - wwOut];
                    count[curH, wayIn] += count[curH - 1, 1 - wwOut];

                    count[curH, wayIn]++;
                    wayOut[curH, wayIn] = wOut2;
                }
            }

            curH = h-1;
            wayIn = 0;

            Int64 result = 0;

            do
            {
                Int64 totalLeaves = (Int64)Math.Pow(2, h);
                result++;
                if (h == 0)
                    break;
                if (wayIn == 0)
                {
                    if (exit <= totalLeaves / 2)
                    {
                        wayIn = 1 - wayIn;
                    }
                    else
                    {
                        result += count[h - 1, 1 - wayIn];
                        wayIn = wayIn;
                        exit -= totalLeaves / 2;
                    }
                }
                else
                {
                    if (exit > totalLeaves / 2)
                    {
                        wayIn = 1 - wayIn;
                        exit -= totalLeaves / 2;
                    }
                    else
                    {
                        result += count[h - 1, 1 - wayIn];
                        wayIn = wayIn;
                    }
                }
                h--;
            }
            while (true);
            result--;
            ioHelper.WriteLine(result.ToString());
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			//p1 o = new p1();
			//o.foo();

			//p2 o = new p2();
			//o.foo();

			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int h = int.Parse(sp[0]);
			Int64 n = Int64.Parse(sp[1]);

			Console.WriteLine(bar(h, n, 'L'));
		}

		private long bar(int h, Int64 n, char next)
		{
			if (h == 0)
				return 0;

			Int64 l = 1L << (h - 1);
			if (next == 'L')
			{
				if (n <= l)
				{
					return 1 + bar(h - 1, n, 'R');
				}
				else
				{
					return (1L << h) + bar(h - 1, n - l, 'L');
				}
			}
			else
			{
				if (n <= l)
				{
					return (1L << h) + bar(h - 1, n, 'R');
				}
				else
				{
					return 1 + bar(h - 1, n - l, 'L');
				}
			}
		}
	}
}


using System;

namespace Codeforces
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] input = Console.ReadLine ().Split (' ');
			int h = Convert.ToInt32 (input [0]);
			ulong n = Convert.ToUInt64 (input [1]);
			int i = 0, b= 0, j = 1;
			ulong k = 0, residue = 0, branch = 0, side = 0, total = 0, leafs = 1;
			bool line = true;
			while (i < h) {
				leafs = leafs * 2;
				i += 1;
			}

			side = leafs;
			residue = n;
			i = 0;
			while (i < h) {
				side = side / 2;
				if (residue >= 2) {
					if (residue <= side) {
						if (line == true) {
							line = !line;
							total += 1;
						} else {
							b = i;
							k = 1;
							branch = 0;
							while (b < h) {
								branch += k;
								k = k * 2;
								b += 1;
							}
							total += branch + 1;
						}
					} else {
						residue = residue - side;
						if (line == false) {
							line = !line;
							total += 1;
						} else {
							b = i;
							k = 1;
							branch = 0;
							while (b < h) {
								branch += k;
								k = k * 2;
								b += 1;
							}
							total += branch + 1;
						}
					}
				} else if (residue == 0) {
					if (line == false) {
						line = !line;
						total += 1;
					} else {
						b = i;
						k = 1;
						branch = 0;
						while (b < h) {
							branch += k;
							k = k * 2;
							b += 1;
						}
						total += branch + 1;
					}
				} else {
					if (line == true) {
						line = !line;
						total += 1;
					} else {
						b = i;
						k = 1;
						branch = 0;
						while (b < h) {
							branch += k;
							k = k * 2;
							b += 1;
						}
						total += branch + 1;
					}
				}
				i += 1;
				j = j * 2;
			}

			Console.WriteLine (total);
		}
	}
}


#region imports
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

#endregion

namespace CodeForces
{
    class Problem
    {
        const bool IsContest = true;

        private void Solve()
        {
            var h = _.NextInt();

            var n = Convert.ToString(_.NextLong() - 1, 2).PadLeft(h, '0').ToCharArray().Select(x => x - '0').ToArray();

            long nVisited = 0;
            var nextDir = 0;
            const long long1 = 1;
            for (var level = 0; level < h; level++)
            {
                var dir = n[level];
                if (dir != nextDir)
                {
                    nVisited += long1 << (h - level);
                }
                else
                {
                    nVisited += 1;
                }
                nextDir = (dir + 1) % 2;
            }
            _.WriteLine(nVisited);
        }

        #region shit
        private readonly InOut _ = new InOut(IsContest);
        static void Main(string[] args)
        {
            var p = new Problem();
            p.Solve();
            p._.Close();
        }
    }
    class InOut
    {
        private const string InputFile = "input.txt";
        private const string OutputFile = "output.txt";
        public StreamWriter Cout { get; private set; }
        public StreamReader Cin { get; private set; }
        private void SetConsoleIo()
        {
            Cin = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            Cout = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
        }
        private void SetFileIo(string inputFile, string outputFile) { Cin = new StreamReader(inputFile); Cout = new StreamWriter(outputFile); }
        public InOut() { SetConsoleIo(); }
        public InOut(string inputFile, string outputFile) { SetFileIo(inputFile, outputFile); }
        public InOut(bool isContest) { if (isContest) SetConsoleIo(); else SetFileIo(InputFile, OutputFile); }
        public void WriteLine(object x) { Cout.WriteLine(x); }
        public void Close() { Cin.Close(); Cout.Close(); }
        public void WriteLine(string format, params object[] args) { Cout.WriteLine(format, args); }
        private int _pos;
        private string[] _tokens;

        private string[] NextStringArray() { return Cin.ReadLine().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); }
        public string NextToken()
        {
            while (_tokens == null || _pos == _tokens.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                _tokens = NextStringArray();
                _pos = 0;
            }
            return _tokens[_pos++];
        }
        public int NextInt() { return int.Parse(NextToken()); }
        public long NextLong() { return long.Parse(NextToken()); }
        public double NextDouble() { return double.Parse(NextToken(), CultureInfo.InvariantCulture); }
        public int[] NextIntArray() { return NextStringArray().Select(int.Parse).ToArray(); }
        public byte[] NextByteArray() { return NextStringArray().Select(byte.Parse).ToArray(); }
        public long[] NextLongArray() { return NextStringArray().Select(long.Parse).ToArray(); }
        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static bool l;
        static BigInteger ans, he;

        static BigInteger pow2(int t)
        {
            BigInteger res = 1;
            for (int i = 0; i < t; i++)
                res *= 2;
            return res;
        }

        static void bin(BigInteger left, BigInteger right, BigInteger go)
        {
            while (left != right)
            {
                BigInteger mid = (left + right) / 2;
                if (mid < go)
                {
                    left = mid + 1;
                    if (l)
                    {
                        ans += he;
                    }
                    else
                        ans++;
                    l = true;
                }
                else
                {
                    right = mid;
                    if (!l)
                    {
                        ans += he;
                    }
                    else
                        ans++;
                    l = false;
                }
                he /= 2;
            }
        }

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] str = s.Split();
            int h = int.Parse(str[0]);
            he = pow2(h);
            BigInteger n = BigInteger.Parse(str[1]);
            l = true;
            ans = 0;
            bin(1, he, n);
            Console.Write(ans);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int[] arr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            int lvl = arr[0] + 1;
            int n = arr[1], ans = 0, total = 1, totallists = 0 ;
            double lists = Math.Pow(2, arr[0])/ 2, max = Math.Pow(2, arr[0]), min = 1;
            bool direction = true;
            for (int i = 1; i < lvl; i++) {
                totallists += (int)Math.Pow(2, i);
            }
                while (totallists != 0){
                    if (n <= lists && direction == false)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        max = lists;
                        lists = Math.Floor((max + min)/2);
                    }
                    else if (n <= lists && direction == true) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        max = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == true)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == false) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }

                }
                Console.WriteLine(total - 1);
                //Console.ReadKey();
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            var h = (int) Next();
            long n = Next() - 1;

            long sum = 0;

            long l = 0;
            long r = (((long) 1) << h) - 1;
            bool left = true;
            for (; h > 0; h--)
            {
                long mid = (r + l + 1)/2;

                sum++;

                if (mid > n)
                {
                    if (!left)
                    {
                        sum += (((long) 1) << (h - 1)) - 1;
                    }

                    r = mid-1;
                    left = false;
                }
                else
                {
                    if (left)
                    {
                        sum += (((long)1) << h) - 1;
                    }

                    l = mid;
                    left = true;
                }
            }

            writer.WriteLine(sum);
            writer.Flush();
        }

        private static long Next()
        {
            int c;
            long 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';
            }
        }
    }
}


#region imports
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

#endregion

namespace CodeForces
{
    class Problem
    {
        const bool IsContest = true;

        private void Solve()
        {
            var h = _.NextInt();

            var n = Convert.ToString(_.NextLong() - 1, 2).PadLeft(h, '0').ToCharArray();

            //            var level = 0;
            long nVisited = 0;
            var nextDir = 0;
            const long long1 = 1;
            for (var level = 0; level < h; level++)
            {
                var dir = n[level];

                if (level == h - 1)
                {
                    switch (dir)
                    {
                        case '1':
                            nVisited += nextDir == 1 ? 1 : 2;
                            break;
                        case '0':
                            nVisited += nextDir == 1 ? 2 : 1;
                            break;
                        default:
                            Debug.Assert(false);
                            break;
                    }
                }
                else
                {
                    switch (dir)
                    {
                        case '1':
                            nVisited += long1 << (h - level);
                            nextDir = 0;
                            break;
                        case '0':
                            nVisited += 1;
                            nextDir = 1                                ;
                            break;
                        default:
                            Debug.Assert(false);
                            break;
                    }
                }
            }
            _.WriteLine(nVisited);
        }

        #region shit
        private readonly InOut _ = new InOut(IsContest);
        static void Main(string[] args)
        {
            var p = new Problem();
            p.Solve();
            p._.Close();
        }
    }
    class InOut
    {
        private const string InputFile = "input.txt";
        private const string OutputFile = "output.txt";
        public StreamWriter Cout { get; private set; }
        public StreamReader Cin { get; private set; }
        private void SetConsoleIo()
        {
            Cin = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            Cout = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
        }
        private void SetFileIo(string inputFile, string outputFile) { Cin = new StreamReader(inputFile); Cout = new StreamWriter(outputFile); }
        public InOut() { SetConsoleIo(); }
        public InOut(string inputFile, string outputFile) { SetFileIo(inputFile, outputFile); }
        public InOut(bool isContest) { if (isContest) SetConsoleIo(); else SetFileIo(InputFile, OutputFile); }
        public void WriteLine(object x) { Cout.WriteLine(x); }
        public void Close() { Cin.Close(); Cout.Close(); }
        public void WriteLine(string format, params object[] args) { Cout.WriteLine(format, args); }
        private int _pos;
        private string[] _tokens;

        private string[] NextStringArray() { return Cin.ReadLine().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); }
        public string NextToken()
        {
            while (_tokens == null || _pos == _tokens.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                _tokens = NextStringArray();
                _pos = 0;
            }
            return _tokens[_pos++];
        }
        public int NextInt() { return int.Parse(NextToken()); }
        public long NextLong() { return long.Parse(NextToken()); }
        public double NextDouble() { return double.Parse(NextToken(), CultureInfo.InvariantCulture); }
        public int[] NextIntArray() { return NextStringArray().Select(int.Parse).ToArray(); }
        public byte[] NextByteArray() { return NextStringArray().Select(byte.Parse).ToArray(); }
        public long[] NextLongArray() { return NextStringArray().Select(long.Parse).ToArray(); }
        #endregion
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			//p1 o = new p1();
			//o.foo();

			//p2 o = new p2();
			//o.foo();

			p3 o = new p3();
			o.foo();
		}

		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int h = int.Parse(sp[0]);
			Int64 n = Int64.Parse(sp[1]);

			Console.WriteLine(bar(h, n, true));
		}

		private long bar(int h, Int64 n, bool left)
		{
			if (h == 0)
				return 0;

			Int64 l = 1L << (h - 1);
			if (left)
			{
				if (n <= l)
				{
					return 1 + bar(h - 1, n, !left);
				}
				else
				{
					return (1L << h) + bar(h - 1, n - l, left);
				}
			}
			else
			{
				if (n <= l)
				{
					return (1L << h) + bar(h - 1, n, !left);
				}
				else
				{
					return 1 + bar(h - 1, n - l, left);
				}
			}
		}
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var h = sc.Integer();
            var n = sc.Long();
            long l = 1;
            long r = 1L << h;
            long count = 0;
            var goL = true;
            for (int i = 0; i < h; i++)
            {
                var m = (l + r) >> 1;
                //Debug.WriteLine(m);
                count++;
                if (n <= m)
                {
                    if (!goL)
                    {
                        count += 1L << (h - i) - 1;
                    }
                    goL = false;
                    r = m - 1;
                }
                else
                {
                    if (goL)
                    {
                        count += (1L << (h - i)) - 1;
                    }
                    goL = true;
                    l = m + 1;
                }
            }
            IO.Printer.Out.WriteLine(count);

        }

        internal IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; }
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }

    }

}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Linq;
    public class Printer : StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
        }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
        public void Flush() { str.Flush(); }

    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion


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

namespace SharpPrikol
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n % 2 != 0)
                Console.WriteLine("black");
            else
            {
                Console.WriteLine("white\n1 2");
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            const string win = "white";
            const string lose = "black";
            var n = sc.Integer();
            if (n % 2 == 0)
            {
                IO.Printer.Out.WriteLine(win);
                IO.Printer.Out.WriteLine("1 2");
            }
            else IO.Printer.Out.WriteLine("black");
        }
        internal IO.StreamScanner sc;
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}

#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
        public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
        public void Flush() { iStream.Flush(); }
    }
}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    }
}
#endregion


using System;

namespace CSharp
{
    class _493D
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            if (n % 2 == 0)
            {
                Console.WriteLine("white");
                Console.WriteLine("1 2");
            }
            else
            {
                Console.WriteLine("black");
            }
        }
    }
}


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

namespace _493D
{
    class Program
    {
        // בתור היריב המרחק יהיה אי-זוגי
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            if (n % 2 == 0)
            {
                Console.WriteLine("white");
                Console.WriteLine("1 2");
            }
            else
                Console.WriteLine("black");

        }
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public object Solve()
    {
        int n = ReadInt();
        if (n % 2 == 0)
        {
            Write("white");
            Write("1 2");
        }
        else
            Write("black");

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("numbers.in");
        //writer = new StreamWriter("numbers.out");
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write

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

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

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

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

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

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

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

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

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

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

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

    #endregion
}


using System;
using System.Collections.Generic;
namespace ConsoleApplication4
{
    class Program
    {

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

            if (n % 2 == 0)
            {
                Console.WriteLine("white");
                Console.WriteLine("1 2");
            }
            else
                Console.WriteLine("black");
        }
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();

        /*
         * クイーン
         *
         * たて、よこ、ななめ
         * 駒があったら取る
         *
         * n*nチェス盤
         *
         * (1,1)に白
         * (1,n)に黒
         * それ以外全部緑
         *
         * 白先手
         *
         * 必ず駒を取る
         *
         * 駒を取られる or 駒を取れない 負け
         *
         * 勝つほう
         */

        /*
         * 2 w 1 2
         * 3 b
         * 4 w 1 2
         */

        if (N % 2 == 0)
        {
            Console.WriteLine("white");
            Console.WriteLine("1 2");
        }
        else
        {
            Console.WriteLine("black");
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
    int n;
    long k;
    public void solve(TextReader input, TextWriter output) {
        var inp = input.ReadLine().Split(' ');
        n = int.Parse(inp[0]);
        k = long.Parse(inp[1]);

        long res = solve();

        if (res == -1)
            output.WriteLine(-1);
        else
            output.WriteLine(toStringBits(res));
    }

    long solve()
    {
        int mid = n / 2;

        for (long i = 0; i < (1 << mid); i++)
        {
            long count = (1L << mid) - i;
            if (n % 2 == 0)
                count -= i;

            if (count <= 0)
                return -1;

            if (k >= count)
            {
                k -= count;
                continue;
            }

            if(n%2 == 0)
                return (i << mid) + calc(i, (1L << mid) - i, mid);
            else
                return (i << mid) + calc(i / 2, i / 2 + (1L << mid) - i, mid);
        }

        return -1;
    }

    long calc(long l, long r, int pos)
    {
        if (pos == 0)
            return 0;

        long count = (r + r % 2) / 2 - (l + l % 2) / 2;

        if (count > k)
        {
            l += l % 2;
            r += r % 2;
            return calc(l / 2, r / 2, pos - 1);
        }
        else
        {
            k -= count;
            return (1 << (pos - 1)) + calc(l / 2, r / 2, pos - 1);
        }
    }

    public string toStringBits(long l)
    {
        string res = "";
        for (int i = n-1; i >= 0; i--)
        {
            var x = l & (1L << i);
            if (x > 0)
                res += "1";
            else
                res += "0";
        }

        return res;
    }
}

class CaideConstants {
    public const string InputFile = null;
    public const string OutputFile = null;
}
public class Program {
    public static void Main(string[] args) {
        Solution solution = new Solution();
        using (System.IO.TextReader input =
                CaideConstants.InputFile == null ? System.Console.In :
                        new System.IO.StreamReader(CaideConstants.InputFile))
        using (System.IO.TextWriter output =
                CaideConstants.OutputFile == null ? System.Console.Out:
                        new System.IO.StreamWriter(CaideConstants.OutputFile))

            solution.solve(input, output);
    }
}


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

namespace AprilFools
{
    internal class Program
    {
        private const string TestIn = @"..\..\In\Text.in";
        private const string TestOut = @"..\..\In\Text.out";

        private static void Solve()
        {
            var nums = ReadIntArray();
            var n = nums[0];
            var k = nums[1];
            var nk = n - k;
            var nmul = nk;
            var kmul = k;

            // factorial n
            long kf = kmul;
            while (--k > 1)
            {
                kf *= kmul;
                kf = kf%1000000007;
            }

            long nkp = nk;
            while (--nk > 0)
            {
                nkp *= nmul;
                nkp = nkp%1000000007;
            }

            Console.WriteLine(((nkp * kf) % 1000000007));
        }

        public static string Multiply(string source, int multiplier)
        {
            StringBuilder sb = new StringBuilder(multiplier * source.Length);
            for (int i = 0; i < multiplier; i++)
            {
                sb.Append(source);
            }

            return sb.ToString();
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(TestIn));
                Console.SetOut(new StreamWriter(TestOut));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.Out.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                //Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace AprilFools
{
    internal class Program
    {
        private const string TestIn = @"..\..\In\Text.in";
        private const string TestOut = @"..\..\In\Text.out";

        private static void Solve()
        {
            var nums = ReadIntArray();
            var n = nums[0];
            var k = nums[1];
            var nk = n - k;
            var nmul = nk;
            var kmul = k;

            // factorial n
            long kf = kmul;
            while (--k > 1)
            {
                kf *= kmul;
            }

            long nkp = nk;
            while (--nk > 0)
            {
                nkp *= nmul;
            }

            Console.WriteLine((nkp * kf) % 1000000007);
        }

        public static string Multiply(string source, int multiplier)
        {
            StringBuilder sb = new StringBuilder(multiplier * source.Length);
            for (int i = 0; i < multiplier; i++)
            {
                sb.Append(source);
            }

            return sb.ToString();
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(TestIn));
                Console.SetOut(new StreamWriter(TestOut));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.Out.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                //Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace AprilFools
{
    internal class Program
    {
        private const string TestIn = @"..\..\In\Text.in";
        private const string TestOut = @"..\..\In\Text.out";

        private static void Solve()
        {
            var nums = ReadIntArray();
            var n = nums[0];
            var k = nums[1];
            var nk = n - k;
            var nmul = nk;
            var kmul = k;

            // factorial n
            long kf = kmul;
            while (--k > 1)
            {
                kf *= kmul;
            }

            long nkp = nk;
            while (--nk > 0)
            {
                nkp *= nmul;
            }

            Console.WriteLine(((nkp % 1000000007) * (kf % 1000000007) % 1000000007));
        }

        public static string Multiply(string source, int multiplier)
        {
            StringBuilder sb = new StringBuilder(multiplier * source.Length);
            for (int i = 0; i < multiplier; i++)
            {
                sb.Append(source);
            }

            return sb.ToString();
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(TestIn));
                Console.SetOut(new StreamWriter(TestOut));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.Out.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                //Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace AprilFools
{
    internal class Program
    {
        private const string TestIn = @"..\..\In\Text.in";
        private const string TestOut = @"..\..\In\Text.out";

        private static void Solve()
        {
            var nums = ReadIntArray();
            var n = nums[0];
            var k = nums[1];
            var nk = n - k;
            var nmul = nk;
            var kmul = k;

            // factorial n
            long kf = kmul;
            while (--k > 1)
            {
                kf *= kmul;
                kf = kf%1000000007;
            }

            long nkp = nk;
            while (--nk > 0)
            {
                nkp *= nmul;
                nkp = nkp%1000000007;
            }

            if (kf == 0) kf = 1;
            if (nkp == 0) nkp = 1;
            Console.WriteLine(((nkp * kf) % 1000000007));
        }

        public static string Multiply(string source, int multiplier)
        {
            StringBuilder sb = new StringBuilder(multiplier * source.Length);
            for (int i = 0; i < multiplier; i++)
            {
                sb.Append(source);
            }

            return sb.ToString();
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(TestIn));
                Console.SetOut(new StreamWriter(TestOut));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.Out.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                //Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}