import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Prac{
    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        public InputReader(InputStream st) {
            this.stream = st;
        }
        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
            c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public int[] nia(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public String rs() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                    c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
    public static class Key {

        private final int x;
        private final int y;

        public Key(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Key)) return false;
            Key key = (Key) o;
            return x == key.x && y == key.y;
        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

    }

    static PrintWriter w = new PrintWriter(System.out);
    static long mod=998244353L,mod1=1000000007;
    static int co[][];
    static void dsort(){
        Arrays.parallelSort(co,(o1,o2)->o1[0]!=o2[0]?o1[0]-o2[0]:o1[1]-o2[1]);
    }
     static long  power(long x, long y) {
        long temp=0;
        if( y == 0)
            return 1;
        temp = power(x, y/2);
        if (y%2 == 0)
            return (temp*temp)%mod1;
        else
            return (((x*temp)%mod1)*temp)%mod1;
    }
    static long modInverse(long a, long m){
        long num=m;
        long x=1;
        long power=a%mod1;
        while(num>0){
              if(num%2==1){
                  x=(x*power)%mod1;
            }
            num>>=1;
            power=(power*power)%mod1;
        }
        return x;
    }
    static long ncr(int n,int r){
        if(n<r)return 0L;
        long ans=fact[n]/(fact[r]*fact[n-r]);
        return ans;
    }
    static long fact[]=new long[1000005];
    public static void findFact(){
        fact[0]=1;
        for(int i=1;i<=1000000;i++){
            fact[i]=(i*fact[i-1])%mod1;
        }
    }
    static long nCr(int n,int r){
        if(n<r)return 0L;

        return (fact[n]*modInverse((fact[r]*fact[n-r])%mod1,mod1-2))%mod1;
    }
    static Set<String> set = new HashSet<>();

    // Recursive function to generate
    // permutations of the string
    static void Permutation(String str, String ans)
    {

        // If string is empty
        if (str.length() == 0) {

            // Add the generated permutation to the
            // set in order to avoid duplicates
            set.add(ans);
            return;
        }

        for (int i = 0; i < str.length(); i++) {

            // ith character of str
            char ch = str.charAt(i);

            // Rest of the string after excluding
            // the ith character
            String ros = str.substring(0, i)
                         + str.substring(i + 1);

            // Recurvise call
            Permutation(ros, ans + ch);
        }
    }
    public static void main (String[] args)throws IOException{
        InputReader sc=new InputReader(System.in);
        //findFact();
        int n=sc.ni(),k=sc.ni();
        String p="";
        for(int i=1;i<=k;i++){
            p=p+Integer.toString(i);
        }
        Permutation(p,"");
        String s[]=new String[n];
        for(int i=0;i<n;i++){
            s[i]=sc.nextLine();
        }
        int ans=Integer.MAX_VALUE;
        for(String x:set){
            int min=Integer.MAX_VALUE,max=Integer.MIN_VALUE;
            for(int i=0;i<n;i++){
                String te="";
                for(int j=0;j<k;j++){
                    int in=x.charAt(j)-'1';
                    te=te+s[i].charAt(in);
                }
                int num=Integer.parseInt(te);
                min=Math.min(min,num);
                max=Math.max(max,num);
            }
            ans=Math.min(ans,max-min);
        }
        w.println(ans);
        w.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nasko
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int s = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = in.nextInt();
            Arrays.sort(arr);
            for (int i = 0; i < n - 1; ++i) s -= arr[i];
            if (s >= 0) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class ProblemD
{

    static int mod = (int) (1e9+7);
    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args)
    {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();

        Pair[] a = new Pair[n];
        for(int i = 0; i < n; i++)
            a[i] = new Pair(in.nextInt(), in.nextInt());

        Pair[] b = new Pair[m];

        for(int i = 0; i < m; i++)
            b[i] = new Pair(in.nextInt(), in.nextInt());

        TreeSet<Integer>[] list = new TreeSet[n + m];
        for(int i = 0; i < n + m; i++)
            list[i] = new TreeSet<>();

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(a[i].x == b[j].x && a[i].y == b[j].y) continue;
                if(a[i].x == b[j].x){
                    list[i].add(a[i].x);
                    list[j + n].add(a[i].x);
                }
                else if(a[i].y == b[j].y){
                    list[i].add(a[i].y);
                    list[j + n].add(a[i].y);
                }
                else if(a[i].x == b[j].y) {
                    list[i].add(a[i].x);
                    list[j + n].add(a[i].x);
                }
                else if(a[i].y == b[j].x){
                    list[i].add(a[i].y);
                    list[j + n].add(a[i].y);
                }
            }
        }

        TreeSet<Integer> set = new TreeSet<>();
        for(int i = 0; i < n + m; i++){
            if(list[i].size() > 1){
                out.println(-1);
                out.close();
                return;
            }

            if(list[i].size() == 1){
                set.add(list[i].first());
            }
        }

        out.println(set.size() > 1 ? 0 : set.first());
        out.close();
    }

    static class Pair implements Comparable<Pair>
    {

        int x,y;
        int i;

        Pair (int x,int y)
        {
            if(x > y){
                x = x ^ y;
                y = x ^ y;
                x = x ^ y;
            }
                this.x = x;
                this.y = y;
        }

        Pair (int x,int y, int i)
        {
                this.x = x;
                this.y = y;
                this.i = i;
        }

        public int compareTo(Pair o)
        {
            return Integer.compare(this.x, o.x);
        }

        public boolean equals(Object o)
        {
            if (o instanceof Pair)
            {
                Pair p = (Pair)o;
                return p.x == x && p.y==y;
            }
            return false;
        }

        @Override
        public String toString()
        {
            return x + " "+ y + " "+i;
        }

        /*public int hashCode()
        {
            return new Long(x).hashCode() * 31 + new Long(y).hashCode();
        }*/

    }

    static String rev(String s){
        StringBuilder sb=new StringBuilder(s);
        sb.reverse();
        return sb.toString();
    }

    static long gcd(long x,long y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static int gcd(int x,int y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static long pow(long n,long p,long m)
    {
         long  result = 1;
          if(p==0){
            return 1;
          }

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            if(result >= m)
               result %= m;
            p >>=1;
            n*=n;
            if(n >= m)
                n%=m;
        }

        return result;
    }

    static long pow(long n,long p)
    {
        long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            p >>=1;
            n*=n;
        }
        return result;
    }

    static void debug(Object... o)
    {
            System.out.println(Arrays.deepToString(o));
    }

    static class InputReader
    {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
                this.stream = stream;
        }

        public int snext()
        {
                if (snumChars == -1)
                        throw new InputMismatchException();
                if (curChar >= snumChars)
                {
                        curChar = 0;
                        try
                        {
                                snumChars = stream.read(buf);
                        } catch (IOException e)
                        {
                                throw new InputMismatchException();
                        }
                        if (snumChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int nextInt()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                int res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public long nextLong()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                long res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
                int a[] = new int[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextInt();
                }
                return a;
        }

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

        public String readString()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
        }

        public String nextLine()
        {
                int c = snext();
                while (isSpaceChar(c))
                        c = snext();
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
                return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
                public boolean isSpaceChar(int ch);
        }

    }
}


public class A {
    public static void main(String...args) {
        String s = new java.util.Scanner(System.in).next();
        int a, b, num;
        a = 0;
        b = 0;
        num = 0;

        for(int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                for (int j = i + 1; j < s.length(); j++) {
                    if (s.charAt(j) == 'Q') {
                        a++;
                    }
                }
                for (int k = i - 1; k >= 0; k--) {
                    if (s.charAt(k) == 'Q') {
                        b++;
                    }
                }
                num += a * b;
                a = 0;
                b = 0;
            }
        }
        System.out.println(num);
    }
}


import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int b = scn.nextInt();
        int g = scn.nextInt();
        int n = scn.nextInt();

        int min = n - Math.min(b, n);

        int max = Math.min(n, g);
        System.out.println(max - min + 1);

    }
}


import java.util.*;
import java.io.*;

public class CF347A{

	private static InputStream stream;
	private static PrintWriter pw;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;

	private static void soln(){
		int n = nextInt();
		int[] arr = nextIntArray(n);
		Arrays.sort(arr);
		int temp = arr[0];
		arr[0] = arr[n-1];
		arr[n-1] = temp;
		pArray(arr);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main  {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(in, out);
		out.close();
	}

	static class TaskE {
		public void solve(InputReader in, PrintWriter out) {
			int h = in.nextInt();
			int w = in.nextInt();
			int[][] a = new int[h + 1][w + 1];
			for (int i = 1; i <= h; i++) {
				String s = in.next();
				for (int j = 0; j < s.length(); j++) {
					if (s.charAt(j) == '*')
						a[i][j + 1]++;
				}
			}

			int ans = 0;
			if (a[1][1] == 1)
				ans++;
			int i = 1, j = 1;
			while (i + 1 <= h || j + 1 <= w) {
				if (j + 1 <= w && a[i][j + 1] == 1) {
					j++;
					ans++;
				} else if (i + 1 <= h && a[i + 1][j] == 1) {
					i++;
					ans++;
				} else {
					if (j + 1 <= w)
						j++;
					else
						i++;
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreElements()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.HashSet;
import java.util.Scanner;
public class CavePainting {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        long k=sc.nextLong();
        HashSet<Long> hs=new HashSet<>();

        for(int i=1;i<=k;i++)
        {
            long d=n%i;
            if(hs.contains(d))
            {
                System.out.println("No");
                return;
            }
            else
            {
                hs.add(d);
            }
        }
        System.out.println("Yes");
    }
}


// package Practice2.CF200;

import java.util.Scanner;

public class CF201A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt();
       if(x==3)
            System.out.println(5);
        else {
            int i = 1;
            while (x > (float) (i * i + 1) / 2)
                i = i + 2;
            System.out.println(i);
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;
public class main {
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int l=sc.nextInt();
        int a[]=new int[n];
        int aa[]=new int[n];
        int bb[]=new int[n];
        int b[]=new int[n];
        for (int i=0;i< n;i++)
        {
            a[i]=sc.nextInt();
        }
        for (int i=0;i< n;i++)
        {
            b[i]=sc.nextInt();
        }
        aa[0]=(l-a[n-1])+a[0];
        bb[0]=(l-b[n-1])+b[0];
        for (int i=1;i<n;i++)
        {
            aa[i]=a[i]-a[i-1];
            bb[i]=b[i]-b[i-1];
        }
        int f=1;
        for(int i=0;i<n;i++)
        {
         int cnt=0;
         for(int j=0;j<n;j++)
         {
          if(aa[j]==bb[j])
          {
           cnt++;
          }
         }
         if(cnt==n)
         {
          f=0;
          break;
         }
         else
         {
          int temp=bb[0];
          for(int k=0;k<n;k++)
          {
           if(k==n-1)
            bb[k]=temp;
           else
            bb[k]=bb[k+1];
          }

         }
        }
        if(f==0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R258_Div1_MemSQL_A //Name: Eevee
{
	FastReader in;
	PrintWriter out;

	public static void main(String[] args)  {
		new R258_Div1_MemSQL_A().run();
	}

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		String[] p = new String[]{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"};

		int n = in.nextInt();
		String s = in.next();

		for (String st : p)
		{
			if (st.length() == n)
			{
				boolean ok = true;
				for (int j = 0; j < n; j++)
					if (s.charAt(j) != '.' && s.charAt(j) != st.charAt(j))
						ok = false;

				if (ok)
				{
					out.println(st);
					return;
				}
			}
		}

	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}


import java.util.*;
import java.io.*;

public class recycle {

	public static void main(String[] args) throws IOException {

		FastScanner qwe = new FastScanner(System.in);
		long[] fact = new long[21];
		fact[0] = 1;
		for (int i = 1; i < fact.length; i++) {
			fact[i] = fact[i-1]*i;
		}

		int n = qwe.nextInt();
		int even = 2*n-2;
		System.out.println(fact[even]/fact[even/2]/fact[even/2]);

	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws IOException{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws IOException {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public String next() throws IOException {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws IOException{
			return Float.parseFloat(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public String nextLine() throws IOException{
			return br.readLine().trim();
		}
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		st = new StringTokenizer(br.readLine());

		long n = Long.parseLong(st.nextToken());
		int m = Integer.parseInt(st.nextToken());

		long[][] a = new long[m][m];
		a[0][0] = 1l;
		a[0][m - 1] = 1l;

		for (int i = 1; i < a.length; i++) {
			a[i][i - 1] = 1l;
		}

		long[][] ans = pow(a, n + 1);
		System.out.println(ans[0][m - 1]);
		// print();
	}

	static void print(long[][] a) {
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a.length; j++) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}

	static long[][] pow(long[][] a, long n) {
		if (n == 1) {
			return a;
		}

		if (n % 2 == 0) {
			long[][] tmp = pow(a, n / 2);
			return multiply(tmp, tmp);
		} else {
			long[][] tmp = pow(a, n / 2);
			return multiply(multiply(tmp, tmp), a);
		}
	}

	static int MOD = 1000000007;

	static long[][] multiply(long[][] a, long[][] b) {
		int n = a.length;
		long[][] ans = new long[n][n];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				long sum = 0l;
				for (int k = 0; k < n; k++) {
					long temp = (a[i][k] * b[k][j]) % MOD;
					sum = (sum + temp) % MOD;
				}
				ans[i][j] = sum;
			}
		}

		return ans;
	}

}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.regex.*;

public class Main{
	 static long dp[][][][]=new long [16][16][16][4];
	 static void ini() {
		 for(int i=0;i<16;i++) {
			 for(int j=0;j<16;j++) {
				 for(int k=0;k<16;k++) {
					 for(int l=0;l<4;l++) {
						 dp[i][j][k][l]=-1L;
					 }
				 }
			 }
		 }
	 }
	 static int chk(long i) {
		 if(i==0L)
			 return 1;
		 else
			 return 0;
	 }
	 static long f(long a,long b,long c,int taken) {
		int got=(int) (a+b+c);
		int have=chk(a)+chk(b)+chk(c);
		if(have==2) {
			if(got==1)
				return 1L;
			else
				return 0L;
		}
		if(dp[(int) a][(int) b][(int) c][taken]!=-1) {
			return dp[(int) a][(int) b][(int) c][taken];
		}
		long ans=0L;
		 if(taken == 0) {
			 if(a!=0)
			 ans+=(a*f(a-1,b,c,1))%mod; ans%=mod;
			 if(b!=0)
			 ans+=(b*f(a,b-1,c,2))%mod; ans%=mod;
			 if(c!=0)
			 ans+=(c*f(a,b,c-1,3))%mod; ans%=mod;
		 }
		 else {
			 ans+=((taken==1 || a==0)?0L:(a*f(a-1,b,c,1))%mod)%mod; ans%=mod;
			 ans+=((taken==2 || b==0)?0L:(b*f(a,b-1,c,2))%mod)%mod; ans%=mod;
			 ans+=((taken==3 || c==0)?0L:(c*f(a,b,c-1,3))%mod)%mod; ans%=mod;
		 }
		 dp[(int) a][(int) b][(int) c][taken]=ans;
		 return ans;
	 }
	public static void main(String[] args)
   {
       InputReader in=new InputReader(System.in);
       PrintWriter pw = new PrintWriter(System.out);
       int n=in.nextInt();
       int total=in.nextInt();
       int t[]=new int[n];
       int g[]=new int[n];
       for(int i=0;i<n;i++) {
    	   t[i]=in.nextInt();
    	   g[i]=in.nextInt();
       }
       long ans=0L;
       for(int i=0;i<(1<<n);i++) {
    	   int sum=0;
    	   int a[]=new int[4];
    	   for(int j=0;j<n;j++) {

    		   if(((i>>j)&1)==1) {
    			   sum+=t[j];
    			   a[g[j]]++;
    		   }
    	   }
    	   if(sum==total) {
    		   ini();
    		   ans=(ans+f(a[1],a[2],a[3],0))%mod;
    	   }
       }
       pw.println(ans);
       pw.flush();
       pw.close();

        }
         private static void debug(Object... o) {
     		System.out.println(Arrays.deepToString(o));
     	}
        static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

        public String readString()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine()
        {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
        public static long mod = 1000000007;
        public static int d;
        public static int p;
        public static int q;

        public static int[] suffle(int[] a,Random gen)
        {
            int n = a.length;
            for(int i=0;i<n;i++)
            {
                int ind = gen.nextInt(n-i)+i;
                int temp = a[ind];
                a[ind] = a[i];
                a[i] = temp;
            }
            return a;
        }

        public static void swap(int a, int b){
            int temp = a;
            a = b;
            b = temp;
        }

       /* public static long primeFactorization(long n)
        {
             HashSet<Integer> a =new HashSet<Integer>();
        	long cnt=0;
            for(int i=2;i*i<=n;i++)
            {
                while(a%i==0)
                {
                    a.add(i);
                    a/=i;
                }
            }
            if(a!=1)
            	cnt++;
                //a.add(n);
            return cnt;
        }*/

        public static void sieve(boolean[] isPrime,int n)
        {
            for(int i=1;i<n;i++)
                isPrime[i] = true;

            isPrime[0] = false;
            isPrime[1] = false;

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

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

        public static long GCD(long a,long b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static void extendedEuclid(int A,int B)
        {
            if(B==0)
            {
                d = A;
                p = 1 ;
                q = 0;
            }
            else
            {
                extendedEuclid(B, A%B);
                int temp = p;
                p = q;
                q = temp - (A/B)*q;
            }
        }

        public static long LCM(long a,long b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int LCM(int a,int b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int binaryExponentiation(int x,int n)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static long binaryExponentiation(long x,long n)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static int modularExponentiation(int x,int n,int M)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result * x)%M;
                x=(x%M*x)%M;
                n=n/2;
            }
            return result;
        }

        public static long modularExponentiation(long x,long n,long M)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result%M * x%M)%M;
                x=(x%M * x%M)%M;
                n=n/2;
            }
            return result;
        }

        public static long modInverse(int A,int M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static long modInverse(long A,long M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static boolean isPrime(int n)
        {

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

            for (int i=5; i*i<=n; i=i+6)
            {
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
            }

            return true;
        }

         public static long[] shuffle(long[] a, Random gen){
                for(int i = 0, n = a.length;i < n;i++){
                    int ind = gen.nextInt(n-i)+i;
                    long d = a[i];
                    a[i] = a[ind];
                    a[ind] = d;
                }
                return a;
            }
         static class pair implements Comparable<pair>{
        	 Long x;
             Long y;
             Integer z;
             pair(long l,long y2,int z){
                 this.x=l;
                 this.y=y2;
                 this.z=z;
             }
              public int compareTo(pair o) {
                     int result = x.compareTo(o.x);
                     if(result==0)
                         result = y.compareTo(o.y);

                 return result;
                 }
              public String toString(){
                 return (x+" "+y);
             }
       }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

//    private static int f(C a, C b) {
//
//        double d = Math.sqrt(d);
//        return 0;
//    }
//
//
//
//
    static class C implements Comparable{

        int x;

        public C(int x){
            this.x=x;

        }
        public int compare(C x, C y){
            return x.x-y.x;

        }

        @Override
        public int compareTo(Object x) {
            x = (C) x;
            return this.compare(this,(C)x);
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new PrintWriter(System.out));

        int[] m = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[][] d = new int[12][7];
        int end = 4;
        for(int i=0;i<12;i++){
            //System.out.println("start");
            int cnt = 0;
            if(end%7 > 0){
                //System.out.println("filling month "+i+" from to "+end+" "+6);
                for(int j=end;j<7;j++){
                    d[i][j] += 1;
                    cnt += 1;
                }

                end = 0;
            }

            //fill it up
            while(cnt != m[i]){
                //System.out.println("filling "+i+" "+cnt+" "+m[i]);
                    for(int j=0;j<7;j++){
                        d[i][j] += 1;
                        cnt += 1;
                        end = j;

                        if(cnt == m[i]){
                            //System.out.println("ending month "+i+" after x days at "+m[i]+" "+end);
                            end += 1;
                            end %= 7;
                            break;
                        }
                    }

            }

        }

        String[] in = br.readLine().split(" ");
        if(in[2].equals("week")){
            int ans = 0;
            int day = Integer.parseInt(in[0]);
            day-=1;
            for(int i=0;i<12;i++){
                ans+=d[i][day];
            }
            System.out.println(ans);
        }else{
            int ans = 0;
            int day = Integer.parseInt(in[0]);
            for(int i=0;i<12;i++){
                if(m[i] >= (day)){
                    ans +=1;
                }
            }
            System.out.println(ans);
        }
        bw.close();
    }

}
//L65644020
    //20151UYO31284713


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static boolean isLeapYear (int year) {
        if (year % 4 == 0) {
            if (year % 100 == 0)
                return year % 400 == 0;
            return true;
        }
        return false;
    }
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        PrintWriter out = new PrintWriter(System.out);
        String first = sc.next() , second = sc.next();
        String names [] = {"sunday" , "monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday"};
        int year = 1 , month = 10;
        boolean found = false;
        while (year < 20000) {
            if (year % 4 == 0) {
                year ++ ;
                month = 10 ;
                continue;
            }

            if (month == - 1) {
                year ++ ;
                month = 10 ;
                continue;
            }

            Calendar calendar = new GregorianCalendar(year , month , 1);
            Calendar calendar2 = new GregorianCalendar(year , month + 1 , 1);
            if (first.equals(names[calendar.get(Calendar.DAY_OF_WEEK) - 1]) &&
                    second.equals(names[calendar2.get(Calendar.DAY_OF_WEEK) - 1])){
            	found = true ;
            }
            month -- ;
        }

        out.print(found ? "YES\n" : "NO\n");
        out.flush();
        out.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String number = reader.readLine();

    if(number.charAt(0) != '1')
      System.out.println("NO");
    else {
      boolean flag = true ;
      int count1 = 0 ;
      int count4 = 0 ;
      for(int i = 0 ; i<number.length() ; i++)
      {
        if(number.charAt(i)=='1')
        {
          count1++;
          count4 = 0 ;
        }
        else if (number.charAt(i)=='4'){
          count4++;
          count1 = 0 ;
        }
        else{
          flag = false ; break ;
        }
        if(count4 > 2 )
        {
          flag = false ;
        break ;

        }

      }
      if(flag == true)
        System.out.println("YES");
      else
        System.out.println("NO");

    }

  }

}


import java.io.*;
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

/**
 * Created by Alexandr on 04.07.2016.
 */

public class Main {
    public static void main(String args[]) throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        String s = sc.nextLine();
        s = sc.nextLine();

        int[] res = new int[4];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '1') {
                res[0] = 1;
                res[3] = 1;
            }
            if (s.charAt(i) == '2') {
                res[0] = 1;
            }

            if (s.charAt(i) == '3') {
                res[0] = 1;
                res[1] = 1;
            }
            if (s.charAt(i) == '4') {
                res[3] = 1;
            }
            if (s.charAt(i) == '6') {
                res[1] = 1;
            }
            if (s.charAt(i) == '7') {
                res[3] = 1;
                res[2] = 1;
            }
            if (s.charAt(i) == '9') {
                res[1] = 1;
                res[2] = 1;
            }
            if (s.charAt(i) == '0') {
                res[1] = 1;
                res[2] = 1;
                res[3] = 1;
            }

        }
        if (res[0] + res[1] + res[2] + res[3] < 4)
            pw.print("NO");
        else pw.print("YES");

        pw.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Problem22 {

	/**
	 * @param args
	 */
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new  InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		  int n= Integer.parseInt(st.nextToken());
		  int x = Integer.parseInt(st.nextToken());
		  int count= 0;
		  for (int i=1;i<=n;i++){
			  if((x/i)<=n&&(x%i)==0)
				  count++;
		  }

		  System.out.println(count);

	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * User: AUtemuratov
 * Date: 02.04.14
 * Time: 9:44
 * To change this template use File | Settings | File Templates.
 */
public class Main {

    static int n,p,k;
    static int b[][] = new int[111][111];
    static int a[] = new int[111];
    public static void main (String [] args) throws Exception {

        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        String s = bf.readLine();
        StringTokenizer tk = new StringTokenizer(s," ");
        n = Integer.parseInt(tk.nextToken());
        p = Integer.parseInt(tk.nextToken());
        k = Integer.parseInt(tk.nextToken());

        if (p-k>1) {
            System.out.print("<< ");
        }

        for (int i=p-k; i<p; i++) {
            if (i<1) continue;
            System.out.print(i + " ");
        }

        System.out.print("(" + p + ") ");

        for (int i=p+1; i<=p+k; i++) {
            if (i>n) break;
            System.out.print(i + " ");
        }

        if (p+k<n) {
            System.out.print(">>");
        }

        pw.close();
    }
}


import java.math.*;
import java.util.*;
//import javafx.util.*;
import java.io.*;

public class Prg10 {

    PrintWriter pw = new PrintWriter(System.out);
    Random rnd = new Random();
    int a;
    long o =0, s, stt;

    void run() {
        s = nl();
        long[] m = new long[8];
        for(int q=0; q<8; q++) m[q] = nl();
        stt = System.currentTimeMillis();
        rec(m, 0);
        pw.print(o);
        pw.flush();
    }

    void rec(long[] m, long cur){
        if(System.currentTimeMillis()-stt>500) return;
        o = Math.max(o, cur);
        for(int q=0; q<8; q++){
            if((s-cur)%(q+1)>0) continue;
            long need = (s-cur)/(q+1);
            if(m[q]>=need){
                o = s;
                return;
            }
        }
        for(int q=7; q>=0; q--){
            long can = Math.min(m[q], (s-cur)/(q+1));
            for(long w=Math.max(1, can-10); w<=can; w++){
                m[q]-=w;
                rec(m, cur+(q+1)*w);
                m[q]+=w;
            }
        }
    }

    static class PyraSort {

        private static int heapSize;

        public static void sort(long[] a) {
            buildHeap(a);
            while (heapSize > 1) {
                swap(a, 0, heapSize - 1);
                heapSize--;
                heapify(a, 0);
            }
        }

        private static void buildHeap(long[] a) {
            heapSize = a.length;
            for (int i = a.length / 2; i >= 0; i--) {
                heapify(a, i);
            }
        }

        private static void heapify(long[] a, int i) {
            int l = 2 * i + 2;
            int r = 2 * i + 1;
            int largest = i;
            if (l < heapSize && a[i] < a[l]) {
                largest = l;
            }
            if (r < heapSize && a[largest] < a[r]) {
                largest = r;
            }
            if (i != largest) {
                swap(a, i, largest);
                heapify(a, largest);
            }
        }

        private static void swap(long[] a, int i, int j) {
            a[i] ^= a[j] ^= a[i];
            a[j] ^= a[i];
        }
    }

    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Prg10().run();
            }
        }, "1", 1 << 28).start();
    }

    InputStream is = System.in;
    private byte[] inbuf = new byte[1<<16];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private String nline(){
        int b = readByte();
        StringBuilder sb = new StringBuilder();
        while (b!=10) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
}


import java.util.*;
public class Tournament {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
        int T = scn.nextInt();
        while (T-- > 0)
        {
        	int N = scn.nextInt();
        	System.out.println( (int)Math.pow(2, N) - 1);

        }
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int t =scn.nextInt();
		while(t-->0){
			long n=scn.nextLong();
			if(n%2==0){
				System.out.println(n/2+" "+n/2);
			}else{
				boolean f=false;
				long val=0;
				for(long i=2;i*i<=n;i++){
					if(n%i==0){
						val = i;
						break;
					}
				}
				if(val==0){
					System.out.println(1+" "+(n-1));
				}else{
				  long m= n/val;

				System.out.println(m+" "+(val-1)*m);
				}
			}
		}

	}

}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1 = sc.nextInt();  //人数
        int a2 = sc.nextInt();
        int k1 = sc.nextInt();  //罚票
        int k2 = sc.nextInt();
        int n = sc.nextInt();
        int n1 = n;
        int n2 = n;
        int max = 0;
        int min = 0;
        n2 -= (a1*(k1-1)+a2*(k2-1));
        if(n2>0)
            min = Math.min(n2, (a1 + a2));
        if(k1<k2){
            if(k1*a1>=n1){
                max = n1/k1;
            }else{
                max = a1;
                n1 -= max*k1;
                max += Math.min(n1 / k2, a2);
            }
        }else{
            if(k2*a2>=n1){
                max = n1/k2;
            }else{
                max = a2;
                n1 -= max*k2;
                max += Math.min(n1 / k1, a1);
            }
        }
        System.out.println(min+" "+max);
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        int c = (int)'a';
        for(int i=0;i<s.length();i++)
        {
        	int x = (int)s.charAt(i);
        	if(x<c)
        	{
        		continue;
        	}
        	else
        	{
        		if(x==c)
        		{
        			c = c+1;
        		}
        		else
        		{
        			out.println("NO");
        			out.close();
        			System.exit(0);
        		}
        	}
        }
        out.println("YES");
        out.close();
    }

}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

	public static void main (String[] args) throws java.lang.Exception
{

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> stringuri= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

		String str=input.next();

		int links=0;
		int pearls=0;
		for(int j=0;j<str.length();j++) if(str.charAt(j)=='-') links++;
			else pearls++;

if(pearls>0)
		{if(links%pearls==0) System.out.println("YES");
		else System.out.println("NO");}

		 else System.out.println("YES");

	}

	}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CF_245B {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();

        int[] b = new int[n];
        for(int i=0; i<n; i++) b[i] = sc.nextInt();

        if(n<=1){
            System.out.println(0);
            return;
        }

        int max = 0;

        for(int i=1; i<n; i++){
            int l=i-1;
            int r=i;
            int count = 0;
            if (b[l]==b[r] && b[r]==x){
                int act = 3;
                while(l>=0 && r<n && b[l]==b[r]){
                    while(l>0 && b[l-1]==b[l]){
                        l--;
                        act++;
                    }
                    while(r<n-1 && b[r+1]==b[r]){
                        r++;
                        act++;
                    }
                    if(act>=3) {
                        count+=act;
                        act = 2;
                        l--;
                        r++;
                    } else {
                        break;
                    }

                }
            } else continue;
            max = Math.max(max,count-1);
        }

        System.out.println(max);

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble(){
            return Double.parseDouble(next());
        }
    }

}


import java.util.Scanner;

public class Problem1191A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        if (x % 4 == 1)
            System.out.println(0 + " A");
        else if (x % 4 == 3)
            System.out.println(2 + " A");
        else if (x % 4 == 2)
            System.out.println(1 + " B");
        else
            System.out.println(1 + " A");
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;

public class C630 {

	/*public static void main(String[] args) throws IOException {
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter out= new BufferedWriter(new OutputStreamWriter(System.out));
		int n;
		int sum = 0;
		n = Integer.valueOf(in.readLine());
		BigInteger i ;
		for(i= new BigInteger("7");i.toString().length()<=n;i = i.add(new BigInteger("1")))
		{

			//System.out.print("1");
			if(i.toString().contains("0")||i.toString().contains("1")||i.toString().contains("2")||i.toString().contains("3")||i.toString().contains("4")||i.toString().contains("5")||i.toString().contains("6")||i.toString().contains("9"))
			{
				continue;
			}
			else
			{
				sum++;
			}
		}
		out.write(String.valueOf(sum));
		out.flush();
		out.close();
	}*/
	static long func(int a)
	{
		long r=1;
		for(int i=0;i<a;i++)
		{
			r*=2;
		}
		return r;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter out= new BufferedWriter(new OutputStreamWriter(System.out));
		int n = Integer.valueOf(in.readLine());
		BigInteger m = new BigInteger("0");
		for(int i = 1;i<=n;i++)
		{
			m = m.add(new BigInteger(String.valueOf(func(i))));
		}
		out.write(m+"\n");
		out.flush();
		out.close();
	}

}


import java.io.*;
import java.util.*;

public class cf89{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

        int ind = Math.min(a,b);
        int div = Math.max(a,b);

        int min2 = -1;

        	for(int i=1;i<n;i++){
        	  int aa = a/i;
        	  int bb = b/(n-i);
        	  int min = Math.min(aa,bb);
        	//  System.out.println(min);
        	  min2 = Math.max(min,min2);
        	}

        System.out.println(min2);

	}
}


import java.util.*;
import java.io.*;

public class Round170D {
	public static void main(String[] args) throws IOException {
		getLine();
		n = nextInt();
		a = new int[n];
		getLine();
		for(int i=0; i<n; i++) a[i] = nextInt();
		int bin = binary(1, n);
	//	System.out.println(isOk(4));
		System.out.println(bin);
	}

	static int binary(int x, int y){
	//	System.out.println("binary on "+x+","+y);
		if(x==y) return isOk(x)? x: -1;
		if(y==x+1) return isOk(x)? x: isOk(y)? y: -1;
		int m = (x+y)>>1;
		return isOk(m)? binary(x, m): binary(m+1, y);
	}

	static boolean isOk(int sz){
		size = sz;
		curIter++;
		fal++;
		boolean b = canGet(1);
		//System.out.println(sz+" "+b);
		return b;
	}

	static char curIter = 'a', fal = Character.toUpperCase(curIter);

	static int size = 0;

	static boolean canGet(int mask){
	//	System.out.println(mask+" "+cur);
	//	if(cur==n) System.out.println("OH YEAH");
		int cur = -1;
		for(int i=n; i>=0; i--){
			if((mask&(1<<i))!=0){
				cur = i;
				break;
			}
		}
		cur++;
	//	System.out.println(mask+" "+cur);
		if(cur==n) return true;
		if(dp[mask]==curIter || dp[mask]==fal) return dp[mask]==curIter;
		if(!can(mask, a[cur])){
			dp[mask] = fal;
			return false;
		}
		int M = mask;
		if(Integer.bitCount(mask)+1<=size){
	//		System.out.println(Integer.bitCount(mask)+" "+size+" calling");
			if(canGet((M^(1<<cur)))){
				dp[mask] = curIter;
				return true;
			}
		}
		for(int i=0; i<cur; i++){
			M = mask;
			if((M&(1<<i))!=0){
				M ^= (1<<i);
				M ^= (1<<cur);
				if(canGet(M)){
					dp[mask] = curIter;
					return true;
				}
			}
		}
		dp[mask] = fal;
		return false;
	}

	static boolean can(int mask, int sum){
		HashSet<Integer> set = new HashSet<Integer>();
		for(int s=0; s<n; s++) if((mask&(1<<s))!=0){
			set.add(a[s]);
		}
		for(int s=0; s<n; s++){
			if((mask&(1<<s))!=0){
				if(set.contains(sum-a[s])) return true;
			}
		}
		if(Integer.bitCount(mask)<size && set.contains(sum)) return true;
		return false;
	}

	static final int SIZE = 23;

	static char[] dp = new char[(1<<SIZE)];

//	static boolean[][] can = new boolean[(1<<SIZE)][SIZE];

	static int[] a;
	static int n;

	static void getLine() throws IOException {
		st = new StringTokenizer(rd.readLine());
	}

	static int nextInt(){
		return Integer.parseInt(st.nextToken());
	}

	static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	static StringTokenizer st;

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Main().new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Main solver = new Main();
		solver.solve(1, in, out);
		out.close();
	}

	// prefix sum
	public void solve(int testNumber, Scanner in, PrintWriter out) {
		char[] s1 = in.readLine().toCharArray();
		char[] s2 = in.readLine().toCharArray();

		int s1p = 0, s1m = 0, s2p = 0, s2m = 0, q = 0;
		for(int i = 0; i < s1.length; i++) {
			if(s1[i] == '+') s1p++;
			else if (s1[i] == '-') s1m++;
			if(s2[i] == '+') s2p++;
			else if (s2[i] == '-') s2m++;
			else q++;
		}
		int p = s1p - s2p;
		int m = s1m - s2m;
		if(Math.abs(p) + Math.abs(m) != q) {
			out.println(0);
		} else {
			long num = fact(p + m) / (fact(p) * fact(m));
			long den = (long) Math.pow(2, p + m);
			double ans = num * 1.0 / den;
			out.println(ans);
		}
	}

	public long fact(int n) {
		long ret = 1;
		for(int i = 1; i <= n; i++) ret *= i;
		return ret;
	}

	class Scanner {

		BufferedReader br;
		StringTokenizer in;

		public Scanner(InputStream inputStream) {
			br = new BufferedReader(new InputStreamReader(inputStream));
		}

		public String next() {
			return hasMoreTokens() ? in.nextToken() : null;
		}

		public String readLine() {
			try {
				return br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}

		boolean hasMoreTokens() {
			while (in == null || !in.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				in = new StringTokenizer(s);
			}
			return true;
		}

		public String ns() {
			return next();
		}

		public int ni() {
			return Integer.parseInt(ns());
		}

		public long nl() {
			return Long.parseLong(ns());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

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


//package CodeForces.C553;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class A {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int len = in.nextInt();
            final String s = in.next();
            final String com = "ACTG";
            int ans = Integer.MAX_VALUE;
            for (int i=0;i<s.length()-3;i++) {
                int temp = 0;
                for (int j=0;j<4;j++) {
                    int diff = Math.abs(s.charAt(i+j) - com.charAt(j));
                    int val = Integer.min(diff, 26-diff);
                    temp+=val;
                }
                ans = Integer.min(ans, temp);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


// package cf652;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;

public class CFA {
    private static final String INPUT = "10 30\n" +
            "2 1";

    private PrintWriter out;
    private FastScanner sc;

    public static void main(String[] args) {
        new CFA().run();
    }

    public void run() {
        sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public void solve() {
        int h1 = sc.nextInt();
        int h2 = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (h1 + (22-14)*a >= h2) {
            System.out.println(0);
        } else if (a <= b) {
            System.out.println(-1);
        } else {
            int diff = h2-h1-(22-14)*a;
            int ans = ceil((double)diff/12/(a-b));
            System.out.println(ans);
        }
    }

    //********************************************************************************************
    //********************************************************************************************
    //********************************************************************************************

    /**
     * If searched element doesn't exist, returns index of first element which is bigger than searched value.

     * If searched element is bigger than any array element function returns first index after last element.

     * If searched element is lower than any array element function returns index of first element.

     * If there are many values equals searched value function returns first occurrence.

     */
    private static int lowerBound(long[] arr, long key) {
        int lo = 0;
        int hi = arr.length - 1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (key <= arr[mid]) {
                hi = mid - 1;
            } else {
                lo = mid + 1;
            }
        }
        return arr[lo] < key ? lo + 1 : lo;
    }

    /**
     * Returns index of first element which is grater than searched value.
     * If searched element is bigger than any array element, returns first index after last element.
     */
    private static int upperBound(long[] arr, long key) {
        int lo = 0;
        int hi = arr.length - 1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (key >= arr[mid]) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        return arr[lo] <= key ? lo + 1 : lo;
    }

    private static int ceil(double d) {
        int ret = (int) d;
        return ret == d ? ret : ret + 1;
    }

    private static int round(double d) {
        return (int) (d + 0.5);
    }

    private static int gcd(int a, int b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    private static long gcd(long a, long b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.longValue();
    }

    private int[] readIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextInt();
        }
        return res;
    }

    private long[] readLongArray(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextLong();
        }
        return res;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }

    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}


import java.util.*;
import java.util.Stack;
import java.io.*;
import java.math.*;

public class Main {

	static int p = 1000000007;
	static Mod mod = new Mod();
	//static int p = 998244353;

	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);

		int t = 1;
		//t = sc.nextInt();

		while (t-- > 0) {

			long n=sc.nextInt(), x=sc.nextInt(), y=sc.nextInt(), dp[]=new long[(int)n+2];
			dp[1]=x;
			dp[2]=min(2*x,x+y);
			for(int i=2; 2*i<=n+1; i++) {
				dp[2*i] = min(dp[i]+y,dp[2*(i-1)]+2*x);
				dp[2*i-1] = min(dp[2*i],dp[2*(i-1)])+x;
			}
			out.print(dp[(int)n]);
		}
		out.flush();
	}

	static int count(int x, int[] arr) {
		int count = 0;

		for (int i = 0; i < arr.length; i++)
			if (arr[i] == x)
				count++;
		return count;
	}

	public static String reverseString(String str) {
		StringBuilder sb = new StringBuilder(str);
		sb.reverse();
		return sb.toString();
	}

	static boolean isPalindrome(String str) {
		int i = 0, j = str.length() - 1;

		while (i < j) {

			if (str.charAt(i) != str.charAt(j))
				return false;

			i++;
			j--;
		}
		return true;
	}

	static void print(int[] arr) {
		for (int i = 0; i < arr.length; i++)
			System.out.print(arr[i] + " ");
		System.out.println();
	}

	public static int abs(int x) {
		return ((x > 0) ? x : -x);
	}

	public static long abs(long x) {
		return ((x > 0) ? x : -x);
	}

	public static int max(int a, int b) {
		return Math.max(a, b);
	}

	public static long max(long a, long b) {
		return Math.max(a, b);
	}

	public static int min(int a, int b) {
		return Math.min(a, b);
	}

	public static long min(long a, long b) {
		return Math.min(a, b);
	}

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

	static int modInverse(int a, int m) {
		int g = gcd(a, m);
		if (g != 1)
			return -1;
		else
			return power(a, m - 2, m);

	}

	// To compute x^y under modulo m
	static int power(int x, int y, int m) {
		if (y == 0)
			return 1;

		int p = power(x, y / 2, m) % m;
		p = (p * p) % m;

		if (y % 2 == 0)
			return p;
		else
			return (x * p) % m;
	}

	static int[] primeGenerator(int num) {
		int length = 0, arr[] = new int[num], a = num, factor = 1;
		if (num % 2 == 0) {
			while (num % 2 == 0) {
				num /= 2;
				factor *= 2;
			}
			arr[length++] = factor;
		}
		for (int i = 3; i * i <= a; i++) {
			factor = 1;
			if (num % i == 0) {
				while (num % i == 0) {
					num /= i;
					factor *= i;
				}
				arr[length++] = factor;
			}
		}
		if (num > 1)
			arr[length++] = num;
		return Arrays.copyOfRange(arr, 0, length);
	}

	static boolean isPrime(int n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		// This is checked so that we can skip
		// middle five numbers in below loop
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	  static class Scanner { BufferedReader br; StringTokenizer st;

	 Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); }

	  Scanner(String fileName) throws FileNotFoundException { br = new
	  BufferedReader(new FileReader(fileName)); }

	  String next() throws IOException { while (st == null || !st.hasMoreTokens())
	  st = new StringTokenizer(br.readLine()); return st.nextToken(); }

	  String nextLine() throws IOException { return br.readLine(); }

	  int nextInt() throws IOException { return Integer.parseInt(next()); }

	  long nextLong() throws NumberFormatException, IOException { return
	  Long.parseLong(next()); }

	  double nextDouble() throws NumberFormatException, IOException { return
	  Double.parseDouble(next()); }

	  boolean ready() throws IOException { return br.ready(); }

	  }

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}
}

class Pair {
	int x;
	int y;

	Pair(int a, int b) {
		x = a;
		y = b;
	}

	void print() {
		System.out.println(this.x + " " + this.y);
	}
}

class Mod{
	static final int MOD = 998244353;

	int add(int x, int y){
		x += y;
	    while(x >= MOD) x -= MOD;
	    while(x < 0) x += MOD;
	    return x;
	}

	int subtract(int x, int y) {
		x -= y;
	    while(x >= MOD) x -= MOD;
	    while(x < 0) x += MOD;
	    return x;
	}

	int mul(int x, int y)
	{
		int result = (int)((long)x*y % MOD);
	    return result>=0?result:result+MOD;
	}

	int binpow(int x, int y)
	{
	    int z = 1;
	    while(y!=0)
	    {
	        if((y & 1)!=0)
	        	z = mul(z, x);
	        x = mul(x, x);
	        y >>= 1;
	    }
	    return z;
	}

	int inv(int x)
	{
	    return binpow(x, MOD - 2);
	}

	int divide(int x, int y)
	{
	    return mul(x, inv(y));
	}

	static final int N =200043;
	int[] fact;

	Mod() {
		fact = new int[N];
	}

	void precalc()
	{
	    fact[0] = 1;
	    for(int i = 1; i < N; i++)
	        fact[i] = mul(fact[i - 1], i);
	}

	int C(int n, int k)
	{
	    return divide(fact[n], mul(fact[k], fact[n - k]));
	}
}


import java.util.Scanner;

public class MoveAahead {

      static String RepeatingCipher(String str){

          if(str.length() == 1){

              return str;

          }else{

              String temp = str.charAt(0) + "";

              int index = 1;

              for(int i = 0;i < str.length();i++){

                    if(index < str.length()){

                        temp = temp.concat(str.charAt(index) + "");

                        index += 2 + i;
                    }

              }
              str = temp;
          }
          return str;
      }

    public static void main(String[] args) {

          Scanner sc = new Scanner(System.in);

        int lim = sc.nextInt();

        String str = sc.next();

      //  long startTime = System.currentTimeMillis();

        System.out.println(RepeatingCipher(str));

      //  System.out.println((System.currentTimeMillis()-startTime)+"ms");
      }
    /*public static int ArrayStabilization(int[] arr){

          int temp[] = new int[arr.length - 2];

          for(int i = 0;i < temp.length;i++){

              temp[i] = arr[i];

          }
          return temp.length-1;
      }*/

}


import java.io.*;

public class InscribedFigures {

    static class FastReader{
        final private int BUFFER_SIZE = 1<<16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader()throws IOException{
            din=new DataInputStream(System.in);
            bufferPointer=bytesRead=0;
            buffer=new byte[BUFFER_SIZE];
        }
        public FastReader(String filename)throws IOException{
            din=new DataInputStream(new FileInputStream(filename));
            bufferPointer=bytesRead=0;
            buffer=new byte[BUFFER_SIZE];
        }
        public String nextLine()throws IOException{
            byte[] buf = new byte[64];
            byte c,count=0;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[count++]=c;
            }
            return new String(buf,0,count);
        }

        public int nextInt()throws IOException {
            int result=0;
            byte c=read();
            byte c1=c;
            while (c<'0' || c>'9'){
                c1=c;
                c=read();
            }
            boolean neg= (c1=='-');
            do {
                result=result*10 + c-'0';
            }while ((c=read())>='0' && c<='9');
            if(neg)
                return -result;
            return result;
        }
        public long nextLong()throws IOException {
            long result=0;
            byte c=read();
            byte c1=c;
            while (c<'0' || c>'9'){
                c1=c;
                c=read();
            }
            boolean neg= (c1=='-');
            do {
                result=result*10 + c-'0';
            }while ((c=read())>='0' && c<='9');
            if(neg)
                return -result;
            return result;
        }
        public double nextDouble()throws IOException{
            double result=0,divisor=1;
            byte c=read(),c1=c;
            while(c<'0' || c>'9'){
                c1=c;
                c=read();
            }
            boolean neg=(c1=='-');

            do {
                result=result*10 + c-'0';
            }while((c=read())>='0' && c<='9');

            if (c=='.'){
                while ((c=read())>='0' && c<='9'){
                    result += (c-'0')/(divisor=divisor*10);
                }
            }
            if(neg)
                return -result;
            return result;
        }
        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer,bufferPointer=0,BUFFER_SIZE);
            if(bytesRead==-1)
                buffer[0]=-1;
        }
        private byte read()throws IOException {
            if(bufferPointer==bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
        public void close()throws IOException {
            if(din==null)
                return;
            din.close();
        }
    }

    public static void main(String[] args) throws IOException {
        //long startTime = System.nanoTime();
        {
            FastReader sc = new FastReader();
            byte n = (byte)sc.nextInt();
            byte[] a = new byte[n];
            int result=0;
            a[0]=(byte)sc.nextInt();
            a[1]=(byte)sc.nextInt();
            if((result+=a[1]+a[0])==5){
                System.out.println("Infinite");
                return;
            }

            for (byte i=2;i<n;i++){
                a[i]=(byte)sc.nextInt();
                if(a[i]+a[i-1]==5){
                    System.out.println("Infinite");
                    return;
                }
                else {
                    if((a[i]+a[i-1]+a[i-2])==6 && a[i]==2)
                        result-=1;
                    result+=a[i]+a[i-1];
                }
            }
            System.out.println("Finite");
            System.out.println(result);

        }//long endTime = System.nanoTime();
        //System.out.println((endTime-startTime) +" ns");
    }
}


import java.util.*;
import java.io.*;
/**
 *
 * @author alanl
 */
public class Main{
    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static char[][]adj = new char[11][11];
    static ArrayList<edge>x = new ArrayList(), y = new ArrayList();
    public static void main(String[] args) throws IOException{
        int xcnt = 0, ycnt = 0;
        for(int i = 0; i<11; i++){
            String s = readLine();
            if(s.length()!=11)continue;
            for(int j = 0; j<11; j++){
                if(s.charAt(j)=='x'){
                    xcnt++;
                    x.add(new edge(i, j));
                }
                else if(s.charAt(j)=='o'){
                    ycnt++;
                    y.add(new edge(i, j));
                }
                adj[i][j] = s.charAt(j);
            }
        }
        solve();
        for(int i = 0; i<11; i++){
            if(i==3||i==7){
                println();
                continue;
            }
            for(int j = 0; j<11; j++){
                if(j==3||j==7)print(" ");
                else print(adj[i][j]);
            }
            println();
        }
        println();
    }
    static void solve() throws IOException{
        int a = readInt(), b = readInt();
        if(a<=3)a--;
        if(b<=3)b--;
        if(a>=7)a++;
        if(b>=7)b++;
        if(a%4==0 && b%4==0)loop(3, 3);
        else if(a%4==0 && b%4==1)loop(3, 7);
        else if(a%4==0 && b%4==2)loop(3, 10);
        else if(a%4==1 && b%4==0)loop(7, 3);
        else if(a%4==1 && b%4==1)loop(7, 7);
        else if(a%4==1 && b%4==2)loop(7, 10);
        else if(a%4==2 && b%4==0)loop(10, 3);
        else if(a%4==2 && b%4==1)loop(10, 7);
        else if(a%4==2 && b%4==2)loop(10, 10);
    }
    static void loop(int a, int b){
        int cnt = 0;
        for(int i = a-3; i<=a; i++){
            for(int j = b-3; j<=b; j++){
                if(adj[i][j]=='.'){
                    adj[i][j] = '!';
                    cnt++;
                }
            }
        }
        if(cnt==0)fill();
    }
    static void fill(){
        for(int i = 0; i<11; i++){
            for(int j = 0; j<11; j++){
                if(adj[i][j]=='.'){
                    adj[i][j] = '!';
                }
            }
        }
    }
    static class edge{
        int x, y;
        edge(int x0, int y0){
            x = x0;
            y = y0;
        }
    }
    static String next () throws IOException {
        while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(input.readLine().trim());
        return st.nextToken();
    }
    static long readLong () throws IOException {
        return Long.parseLong(next());
    }
    static int readInt () throws IOException {
        return Integer.parseInt(next());
    }
    static double readDouble () throws IOException {
        return Double.parseDouble(next());
    }
    static char readChar () throws IOException {
        return next().charAt(0);
    }
    static String readLine () throws IOException {
        return input.readLine().trim();
    }
    static void print(Object b) {
        System.out.print(b);
    }
    static void println(Object b) {
        System.out.println(b);
    }
    static void println() {
        System.out.println();
    }
}


import java.util.Scanner;

public class SummerCamp {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		scan.nextLine();
		String a="";
		for(int i=1;i<=n;i++)
		{
			a+=i;
		}
		System.out.println(a.charAt(n-1));

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;

public class ProblemC {

	static void doit(int m) {
		long[][] a = generate(m);
		int len = a.length;
		int c = 0;
		for (int j = 0 ; j < len ; j++) {
			c += a[len-1][j];
		}
		debug(m, c);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		String[] line = s.readLine().split(" ");
		long n = Long.valueOf(line[0]);
		long t = Long.valueOf(line[1]);

		int fc = -1;
		for (int f = 0 ; f < 60 ; f++) {
			if (Math.pow(2L, f) == t) {
				fc = f;
				break;
			}
		}
		if (fc == -1) {
			out.println(0);
			out.flush();
			return;
		}

		n++;
		fc++;

		int len = 0;
		long nn = n;
		int[] bit = new int[128];
		while (nn >= 1) {
			bit[len] = (int)(nn % 2);
			nn /= 2L;
			len++;
		}

		long[][][] dp = new long[len+1][fc+1][3];
		dp[0][fc][0] = 1;
		for (int i = 0 ; i < len ; i++) {
			for (int f = 0 ; f <= fc ; f++) {
				for (int c = 0 ; c <= 2 ; c++) {
					if (dp[i][f][c] == 0) {
						continue;
					}
					long base = dp[i][f][c];
					if (bit[i] == 0) {
						// use one
						if (f >= 1) {
							dp[i+1][f-1][1] += base;
						}

						// use zero
						dp[i+1][f][c] += base;
					} else {
						// use one
						if (f >= 1) {
							dp[i+1][f-1][c] += base;
						}

						// use zero
						dp[i+1][f][2] += base;
					}
				}
			}
		}

		long ans = dp[len][0][2] + dp[len][0][0];
		if (t == 1) {
			ans--;
		}
		out.println(ans);
		out.flush();
	}

	public static long[][] generate(int m ){
		long[][] a = new long[m+2][m+2];
		a[1][m+1] = 1;
		for (int i = 2 ; i <= m + 1 ; i++) {
			for (int j = 1 ; j <= m + 1 ; j++) {
				if (j == 1) {
					a[i][j] = a[i-1][j+1];
				} else {
					if (j == m + 1) {
						a[i][j] = a[i-1][j-1];
					} else {
						a[i][j] = a[i-1][j-1] ^ a[i-1][j+1];
					}
				}
			}
		}
		return a;
	}

	public static void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int N;
	int M;
	int K;

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();
		M = nextInt();
		K = nextInt();

		int x = 1;
		while (N > 0 && M > 0) {
			if (x == K) {
				out.println(count(N, M) - count(N - 2, M - 2));
				out.close();
				return;
			}
			N -= 2;
			M -= 2;
			x++;
		}

		out.println(0);
		out.close();
	}

	int count(int N, int M) {
		if (N <= 0 || M <= 0)
			return 0;
		int a = (M + 1) / 2;
		int b = (M) / 2;
		return a * ((N + 1) / 2) + b * (N / 2);
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();

			if (s == null) {
				return true;
			}

			st = new StringTokenizer(s);
		}

		return false;
	}
}


import java.util.*;

public class airplane {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int k=in.nextInt();
        int n=in.nextInt();
        int s=in.nextInt();
        int p=in.nextInt();

        int sheet=n/s;
        if (n%s!=0)
            sheet++;

        int total=sheet*k;

        int ans=total/p;
        if (total%p!=0)
            ans++;

        System.out.println(ans);
    }
}


import java.util.Scanner;

public class LuckyYear {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long input = 0;
		long output = 0;

		input = scan.nextInt();

		System.out.println(nextLuckyYear(input));

	}

	public static long nextLuckyYear(long input) {
		long multiplier = 1;
		long result = 0;
		long copy = input;

		while (copy >= 10) {
			copy /= 10;
			multiplier *= 10;
		}

		result = copy + 1;

		result *= multiplier;

		return result - input;
	}

}