import java.util.Scanner;
public class HelloWorld{

     public static void main(String []args){
         int inc=0;
         Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[] a=new int[n];
        for (int i=0;i<n;i++)
        {
             a[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++)
        {
             if(a[i]>=a[k-1] && a[i]>0)
             inc++;
        }
        System.out.println(inc);
     }
}


//package Codeforces.Div2A_107;

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

/*
 * some cheeky quote
 */

public class Main
{
    FastScanner in;
    PrintWriter out;

    public void solve() throws IOException
    {
        int people = in.nextInt();
        int totalBear = in.nextInt() * in.nextInt();
        int totalLimes = in.nextInt() * in.nextInt();
        int totalSalt = in.nextInt();

        int toastBear = in.nextInt();
        int totalToastBear = toastBear * people;
        int toastSalt = in.nextInt() * people;

        int count = 0;
        while (true)
        {
            if (totalBear < totalToastBear || totalSalt < toastSalt || totalLimes < people)
            {
                break;
            }
            totalBear -= totalToastBear;
            totalSalt -= toastSalt;
            totalLimes -= people;
            count++;
        }
        System.out.println(count);

    }

    public void run()
    {
        try
        {
            in = new FastScanner();
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

    public static void main(String[] arg)
    {
        new Main().run();
    }
}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Dubstep
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String ss[] = s.split("WUB");
        for(int i = 0;i<ss.length;i++)
        {
            System.out.print(ss[i]+" ");
        }
    }
}


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

public class KeyRaces {
    public static void main(String[]args) {
        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n=s.nextInt(),v1=s.nextInt(),v2=s.nextInt(),t1=s.nextInt(),t2=s.nextInt();
        int scoreOne=(n*v1)+2*t1;
        int scoreTwo=(n*v2)+2*t2;
        if(scoreOne<scoreTwo)
            System.out.println("First");
        else if(scoreTwo<scoreOne)
            System.out.println("Second");
        else
            System.out.println("Friendship");

    }
    }


import java.util.Scanner;

/**
	 *	Problem Solving
	 *	created on: Jun 16, 2016
	 *	Author : Amr Hendy
*/
public class ProfessorGukiZRobot {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int x1 = input.nextInt();
		int y1 = input.nextInt();
		int x2 = input.nextInt();
		int y2 = input.nextInt();
		int radialSteps =  Math.min(Math.abs(x2-x1), Math.abs(y2-y1));
		int total = radialSteps + (Math.abs(x2-x1) - radialSteps) + ((Math.abs(y2-y1) - radialSteps));
		System.out.println(total);

	}

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Omar Yasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner sc, PrintWriter out) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
            out.println((((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d))));
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.InputMismatchException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, Scan in, PrintWriter out) {
            long nuber = in.scanLong();
            String str = Long.toString(nuber);
            long length = (long) Math.log10(nuber) + 1;
            long totalbit = length;
            long combination = 0;
            while (length > 0) {
                combination = combination | (1 << (length - 1));
                length--;
            }
            long result = -1;
            while (combination > 0) {
                long totalones = 0;
                long ot = 0;
                for (int i = 0; i < totalbit; i++) {
                    if ((combination & (1 << i)) != 0) {
                        if (ot == 0 && str.charAt(i) == '0') {
                            break;
                        }
                        ot = ot * 10 + str.charAt(i) - '0';
                        totalones++;
                    }
                }
                if (ot > 0 && Math.sqrt(ot) == (long) Math.sqrt(ot)) {
                    if (result < totalones) {
                        result = totalones;
                    }
                }
                combination--;
            }
            if (result == -1) {
                totalbit = result - 1;
            }
            out.println(totalbit - result);

        }

    }

    static class Scan {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;

        public Scan() {
            in = System.in;
        }

        public Scan(InputStream inputStream) {
            in = inputStream;
        }

        public int scan() {
            if (total < 0) {
                return 0;
            }
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    System.out.println(e);
                }
                if (total <= 0)
                    return -1;

            }
            return buf[index++];
        }

        public long scanLong() {
            long lng = 0;
            int n = scan();
            while (isWhiteSpace(n))
                n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n) && n != '.') {
                if (n >= '0' && n <= '9') {
                    lng *= 10;
                    lng += n - '0';
                    n = scan();
                } else throw new InputMismatchException();
            }
            if (n == '.') {
                n = scan();
                long temp = 1;
                while (!isWhiteSpace(n)) {
                    if (n >= '0' && n <= '9') {
                        temp /= 10;
                        lng += (n - '0') * temp;
                        n = scan();
                    } else throw new InputMismatchException();
                }
            }
            return neg * lng;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                return true;
            return false;
        }

    }
}


import java.util.*;
import java.math.*;
public class h {
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		long n = br.nextInt();
		BigInteger temp = new BigInteger("1");
		temp = temp.multiply(BigInteger.valueOf(n));
		temp = temp.multiply(BigInteger.valueOf(n-1));
		temp = temp.multiply(BigInteger.valueOf(n-2));
		temp = temp.multiply(BigInteger.valueOf(n-3));
		temp = temp.multiply(BigInteger.valueOf(n-4));
		temp = temp.multiply(temp);
		temp = temp.divide(BigInteger.valueOf(2));
		temp = temp.divide(BigInteger.valueOf(3));
		temp = temp.divide(BigInteger.valueOf(4));
		temp = temp.divide(BigInteger.valueOf(5));

		System.out.println(temp.longValue());
	}
}


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

public class DigitalRoot
{
	public Scanner in = new Scanner(System.in);
	public PrintStream out = System.out;

	public int N;

	public void main()
	{
		N = in.nextInt();

		int x, y, z;
		long res = 0;

		long A, B, C;
		int a, b;

		for(z=1;z<=9;++z) for(x=1;x<=9;++x) for(y=1;y<=9;++y) if(z == d(x*y))
		{
			C = count(9, z);
			A = count(9, x);
			B = count(9, y);

			res += A * B * C;

			for(int k=0; k*9+x <=N;++k)
			{
				a = k*9*9 + 9*x;
				b = k*9*y + x*y;
				res -= count(a, b);
			}
		}

		out.println(res);
	}//end public void main()

	public int d(int x)
	{
		if(x%9 == 0) return 9;
		return x%9;
	}

	public int count(int a, int b)
	{
		if(N < b) return 0;
		return (N - b)/a + 1;
	}

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


import java.io.PrintWriter;
import java.util.Scanner;

public class n148A {

    Scanner in;
    PrintWriter out;

    void solve() {
        int k = in.nextInt();
        int l = in.nextInt();
        int m = in.nextInt();
        int n = in.nextInt();
        int d = in.nextInt();
        boolean used[] = new boolean[1 + d];
        for (int i = 1; i <= d; i++) {
            if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) {
                used[i] = true;
            }
        }
        int kol = 0;
        for (int i = 1; i <= d; i++) {
            if (used[i]) {
                kol++;
            }
        }
        out.println(kol);
    }

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

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

    }

}


import java.util.*;

public class Domino {
	static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {

		helper();
	}

	public static void helper() {

		int n = (int)input();
		int[][] arr = new int[n][2];
		int s1 = 0, s2 = 0;
		for (int i = 0; i < n; i++) {
			arr[i][0] = (int)input();
			arr[i][1] = (int)input();
			s1 += arr[i][0];
			s2 += arr[i][1];
		}

		if ((s1 & 1) == 0 && (s2 & 1) == 0) {
			print(0);
			return;
		}

		if ((s1 & 1) == 1 && (s2 & 1) == 1) {

			for (int i = 0; i < n; i++) {
				if (((arr[i][0] & 1) ^ (arr[i][1] & 1)) == 1) {
					print(1);
					return;
				}
			}
		}

		print(-1);

	}

	public static long input() {
		return scn.nextLong();
	}

	public static String input(int... var) {
		return scn.next();
	}

	public static void TakeInput(int[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = (int)input();
	}

	public static void TakeInput(long[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = input();
	}

	public static void printArray(int[] arr) {
		for (int val : arr)
			print(val + " ");

		print("\n");
	}

	public static void printArray(long[] arr) {
		for (long val : arr)
			print(val + " ");

		print("\n");
	}

	public static <T> void print(T t) {
		System.out.print(t);
	}
	public static void print() {
		System.out.println();
	}
}


import java.util.Scanner;

public class contest17 {
    public static void main(String[] args) {
        try
        {
            Scanner s=new Scanner(System.in);
            int n=s.nextInt();
            int ans=0,min=0;
            int b[]=new int[n];
            int a[]=new int[n];
            for(int i=0;i<n;i++)
            {
                a[i]=s.nextInt();
            }
            min=a[2]-a[0];
            for(int i=0;i<n-2;i++)
            {
                b[i]=a[i+2]-a[i];
                if(b[i]<min)
                    min=b[i];
            }

            for(int i=0;i<n;i++)
            {
                if(b[i]==min)
                {
                    ans=i+1;
                }
            }
            for(int i=0;i<ans;i++)
            {
                    b[i]=a[i];
            }
            for(int i=ans+1;i<n;i++)
            {
                b[i-1]=a[i];
            }
            min=0;
            for(int i=0;i<n-1;i++)
            {
                if(b[i+1]-b[i]>min)
                {
                    min=b[i+1]-b[i];
                }
            }
            System.out.println(min);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }

}


import java.io.Console;
import java.util.Arrays;
import java.io.*;
import java.lang.Integer;

public class problemA  {

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

		BufferedReader in;

		if (System.getProperty("ONLINE_JUDGE") != null) {
                in = new BufferedReader(new InputStreamReader(System.in));
        } else {
                in = new BufferedReader(new FileReader("input.txt"));
        }

        String numApplesString = in.readLine();
        int n = Integer.parseInt(numApplesString);
        String [] weights = in.readLine().split(" ");
        in.close();

        int i = 0;
        int sum = 0;

        while (i < n) {
        	sum += Integer.parseInt(weights[i]);
        	i++;
        }

        if ((sum == n * 200) && (n % 2 == 1)) {
        	System.out.println("NO");
        }
        else if ((sum % 200 == 0 && n > 1))  {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }

    }

}


import java.util.*;
public class password {

    public static void main (String[]args) {
    	Scanner sc=new Scanner(System.in);
    	String x=sc.nextLine();
    	boolean l=x.length()>=5;
    	boolean E=false;
    	boolean e=false;
    	boolean d=false;
    	if(l)
        	for(int i=0 ;i<x.length()&&(!E|!e|!d); i++)
        	{
        		if(x.charAt(i)>='a'&&x.charAt(i)<='z')
        			e=true;
        		else
        		  if(x.charAt(i)>='A'&&x.charAt(i)<='Z')
        		  	E=true;
        		  else
        		  	if(x.charAt(i)>='0'&&x.charAt(i)<='9')
        		  		d=true;
        	}
        System.out.print(l&E&e&d?"Correct":"Too weak");
    }

}


import java.util.Scanner;

public class BigRecursion {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(); int m = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[m];
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
    }

    for(int i=0;i<m;i++){
      b[i] = sc.nextInt();
    }

    int ans = Integer.MAX_VALUE;
    for(int i=0;i<a.length;i++){
      for(int j=0;j<b.length;j++){
        String s = String.valueOf(a[i])+String.valueOf(b[j]);
        String ss = String.valueOf(b[j])+String.valueOf(a[i]);
        if(a[i]==b[j]){
           s = String.valueOf(a[i]);
        }
        ans = Math.min(Math.min(Integer.parseInt(s),Integer.parseInt(ss)),ans);
      }
    }
    System.out.println(ans);
  }
}


import java.util.Scanner;
import java.lang.*;
import java.io.*;

public class pb1
{
	public static void main (String[] args)
	{
		Scanner in = new Scanner(System.in);

		String s1,s2;
		s1 = in.nextLine();
		s1 = s1.toLowerCase();
		s1 = s1.replaceAll("\\s", "");

		char t1[] = s1.toCharArray();
		int c = 0;
		s2 = "aeiouy";
		char t2[] = s2.toCharArray();
		int f = 0;
		for(int i=0; i< 6; i++)
		{
			if(t1[s1.length()-2] == t2[i])
			{
				System.out.println("YES");
				f = 1;
				break;
			}
		}
		if( f == 0 )
			System.out.println("NO");
	}
}


import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class t{
    static Scanner reader=new Scanner(System.in);

    public static void main(String[] args){

      int a =reader.nextInt(),b= reader.nextInt();
      int fw = 0 , d =0 , lw =0;
      for (int i=1;i<=6;i++){

          if(Math.abs(i-a)<Math.abs(i-b)){
              fw++;
          }else if (Math.abs(i-a)>Math.abs(i-b)){
              lw++;
          }else if(Math.abs(i-a)==Math.abs(i-b)){
              d++;
          }
      }
        System.out.println(fw +" "+d+" "+lw);

    }

        }


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

public class Main {

   static class Assertion {
      static void check(boolean e) {
         if (!e) {
            throw new Error();
         }
      }
   }

   // class Scanner {
   // StreamTokenizer in;
   //
   // Scanner(InputStream s) {
   // in = new StreamTokenizer(new BufferedReader(new InputStreamReader(s)));
   // in.resetSyntax();
   // in.whitespaceChars(0, 32);
   // in.wordChars(33, 255);
   // }
   //
   // String next() {
   // try {
   // in.nextToken();
   // return in.sval;
   // } catch (Exception e) {
   // throw new Error();
   // }
   // }
   //
   // int nextInt() {
   // return Integer.parseInt(next());
   // }
   //
   // long nextLong() {
   // return Long.parseLong(next());
   // }
   //
   // double nextDobule() {
   // return Double.parseDouble(next());
   // }
   // }

   Scanner in;
   PrintWriter out;

   void solve() {
      int nOld = in.nextInt();
      int nChilds = in.nextInt();
      if (nOld == 0 && nChilds>0) {
         out.println("Impossible");
      } else {
         int min = 0;
         if (nOld >= nChilds) {
            min += nOld;
         } else {
            min += nOld + (nChilds - nOld);
         }
         int max = nOld + Math.max(0,nChilds - 1);
         out.println(min + " " + max);
      }
   }

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

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


import java.util.*;

public class Main {

    private static int m;
    private static int b;

    private static long sum(long x, long y) {
        return (x + 1) * (y + 1) * (x + y) / 2;
    }

    private static long y(long x) {
        return (long) (-(double) x / m + b);
    }

    private static long x(long y) {
        return m * (b - y);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        m = in.nextInt();
        b = in.nextInt();

        long max = 0;

        for (int y = 0; y <= b; ++y) {
            long s = sum(x(y), y);
            if (max < s)
                max = s;
        }

        System.out.println(max);
    }
}


import java.util.Scanner;

public class ExA {
public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int g = scanner.nextInt();
		int b = scanner.nextInt();

		int counter = 30;

		if (r>=2){
			int n=r/2;
			int rem=r%2;
			if (rem==0){
				counter+=(n-1)*3;
				g-=(n-1)*2;
				b-=(n-1)*2;
			}
			else if (rem==1){
				counter+=n*3;
				g-=n*2;
				b-=n*2;
			}
		}
		if (g>0){
			counter++;
			if (g>=3){
				int n=g/2;
				int rem=g%2;
				if (rem==0){
					counter+=(n-1)*3;
					b-=(n-1)*2;
				}
				else if (rem==1){
					counter+=n*3;
					b-=n*2;
				}
			}
		}
		if (g<=0 && b>0){
			counter++;
		}
		if (b>0) {
			counter++;
			if (b>=3){
				int n=b/2;
				int rem=b%2;
				if (rem==0){
					counter+=(n-1)*3;
				}
				else if (rem==1){
					counter+=n*3;
				}
			}
		}

		System.out.println(counter);
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Gravity_Flip {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}
		Arrays.sort(arr);
		for(int i=0;i<n;i++)
		{
			System.out.print(arr[i]+" ");
		}
	}
}


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

import static java.lang.Math.*;

public class Solution121A {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

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

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

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

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }
        ArrayList<Long> happiens;

        int[] cur =  {4,0,0,0,0,0,0,0,0};

        boolean Generate(){
        	int c = 0;
        	do{
        		if(cur[c] == 4){
        			cur[c] = 7;
        			String s = "";
        			for(int i = 8; i >= 0; i--){
        				s += Integer.toString(cur[i]);
        			}
        			happiens.add(Long.parseLong(s));
        			return true;
        		}
        		if(cur[c] == 0){
        			cur[c] = 4;
        			String s = "";
        			for(int i = 8; i >= 0; i--){
        				s += Integer.toString(cur[i]);
        			}
        			happiens.add(Long.parseLong(s));
        			return true;
        		}

        			cur[c] = 4;
        			c++;
        			if(c >= 9){
        				return false;

        		}

        	}while(true);
        }

        void solve() throws IOException{
        	long l = readInt();
        	long r = readInt();
        	happiens = new ArrayList<Long>();
        	happiens.add((long) 4);
        	boolean c = true;
        	do{
        		c = Generate();
        	}while(c);
        	long max = Long.parseLong("4444444444");
        	happiens.add(max);
        	long summ = 0;
        	int begin = 0, end = 0;
        	for(int i = 0; i < happiens.size(); i++){
        		if(happiens.get(i) >= l){
        			begin = i;
        			break;
        		}
        	}
        	for(int i = 0; i < happiens.size(); i++){
        		if(happiens.get(i) >= r){
        			end = i;
        			break;
        		}
        	}
        	if(begin == end){
        		summ = (r-l+1)*happiens.get(end);
        		out.println(summ);
        		return;
        	}
        	long curIndex = l;
        	for(int i = begin; i < end; i++){
        		summ += (happiens.get(i) - curIndex + 1)*happiens.get(i);
        		curIndex = happiens.get(i)+1;
        	}
        	summ += (r-curIndex + 1)*happiens.get(end);
        	out.println(summ);

        }

        int ModExp(int a, int n, int mod){
        	int res = 1;
        	while (n!=0)
        		if ((n & 1) != 0) {
        			res = (res*a)%mod;
        			--n;
        		}
        		else {
        			a = (a*a)%mod;
        			n >>= 1;
        		}
        	return res;
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


import java.util.Scanner;

public class BeautifulYear {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        char q, w, e, r;
        q = w = e = r = 0;

        while (q == w || q == e || q == r || w == e || w == r || e == r) {
            String yearStr = Integer.toString(year+1);
            q = yearStr.charAt(0);
            w = yearStr.charAt(1);
            e = yearStr.charAt(2);
            r = yearStr.charAt(3);
            year++;
        }
        System.out.println(year);
    }
}


// Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class C {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        int t = 1;
        // t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static void solve() throws IOException {
        Reader sc = new Reader();
        int n=sc.nextInt();
        int x=sc.nextInt();
        int pos=sc.nextInt();
        int l=0;
        int h=n;
        int countless=x-1;
        long fact=1;
        int counthigh=n-x;
        while(l<h)
        {
            int mid=(l+h)/2;
            if(mid<pos)
            {
                l=mid+1;
                fact*=countless;
                fact%=(int)(1e9+7);
                countless--;
            }
            else
            if(mid>pos){
                h=mid;
                fact*=counthigh;
                counthigh--;
                fact%=(int)(1e9+7);
            }
            else{
                l=mid+1;
            }
        }
        if(l>0&&l-1==pos)
        {
            int bacha=countless+counthigh;
            while(bacha>0)
            {
                fact*=bacha;
                fact%=(int)(1e9+7);
                bacha--;
            }
            System.out.println(fact);
            return;
        }
        System.out.println(0);
    }

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

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

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

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

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


import java.io.*;
public class plant{
public static long mod = 1000000007;
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
long p = Long.parseLong(lector.readLine());
if(p==0){
System.out.println("1");
return;
}
long pp = exp(2,p-1);
long res = (((pp)%mod)*((2*pp+1)%mod))%mod;
System.out.println(res);
}
public static long exp(long a,long b){
if(b==0)return 1;
if(b==1)return a;
long t = 0;
if((b&1)==0)t = exp(a,b/2);
return ((b&1)==0)?(t*t)%mod:(exp(a,b-1)*a)%mod;
}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class Task118D {
        long mod = (long) 1e8;
        long dp[][][];

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n1 = in.nextInt();
            int n2 = in.nextInt();
            int k1 = in.nextInt();
            int k2 = in.nextInt();
            dp = new long[n1 + 1][n2 + 1][2];

            for (int i = 0; i <= n1; i++) {
                for (int j = 0; j <= n2; j++) {
                    dp[i][j][0] = -1;
                    dp[i][j][1] = -1;
                }
            }

            long ans = rec(n1, n2, 0, k1, k2) + rec(n1, n2, 1, k1, k2);
            ans %= mod;
            out.println(ans);
        }

        long rec(int n1, int n2, int turn, int k1, int k2) {
            if (dp[n1][n2][turn] != -1)
                return dp[n1][n2][turn];
            if (n1 == 0 && n2 == 0)
                return 1;
            if (turn == 0 && n1 == 0)
                return 0;
            if (turn == 1 && n2 == 0)
                return 0;

            long ans = 0;
            if (turn == 0) {
                for (int i = 1; i <= k1; i++) {
                    if (n1 - i >= 0)
                        ans += rec(n1 - i, n2, 1, k1, k2);
                }
            } else {
                for (int i = 1; i <= k2; i++) {
                    if (n2 - i >= 0)
                        ans += rec(n1, n2 - i, 0, k1, k2);
                }
            }
            ans %= mod;
            dp[n1][n2][turn] = ans;
            return ans;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

        public 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++];
        }

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

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

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

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

        }

    }
}


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

public class Main
{
   static  class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            try {
                br = new BufferedReader(new InputStreamReader(f));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

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

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

    }
    public static void main(String args[])
    {
         InputStream in=System.in;
       //  OutputStream out=System.out;
        FastScanner fs=new FastScanner(in);
        PrintWriter out=new PrintWriter(System.out);

        int arr[]=new int[6];
        for(int i=0;i<6;i++)
            arr[i]=fs.nextInt();
        long sum=0;
        long sum1=0;
        int tr=0;
       for(int i=0;i<6;i++)
        for(int j=i+1;j<6;j++)
            for(int k=j+1;k<6;k++)
            {sum=arr[i]+arr[j]+arr[k];
                sum1=0;
                for(int l=0;l<6;l++)
                    if(l!=i&&l!=j&&l!=k)
                        sum1=sum1+arr[l];
            if(sum1==sum)
                tr=1;

            }

if(tr==1)
    out.println("YES");
else
    out.println("NO");

    //   for(int i=0;i<n;i++)
      // System.out.println(arr[i]);
    out.close();
    }

}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int a = s.nextInt();
        int b = s.nextInt();
        if(a+b<n){
            System.out.println(b+1);
        }else{
            System.out.println(n-a);
        }
    }
}


import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;

public class card_game {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int x=scn.nextInt();
		int y=scn.nextInt();
		if(x==0 && y==0){
			System.out.println(0);
		}
		else if(y-x>0 && x+y>=0){
			int k=y-1;
			System.out.println(4*k+2);
		}
		else if(y-x>=0 && x+y<0){
			int k=Math.abs(x)-1;
			System.out.println(4*k+3);
		}
		else if(y-x<=0 && x+y-1>0){
			int k=x-1;
			System.out.println(4*k+1);
		}
		else if(y-x<0 && x+y-1<=0){
			int k=Math.abs(y);
			System.out.println(4*k);
		}
	}
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import javax.swing.text.InternationalFormatter;
import java.math.*;
public class RATHOD
{
     public static void main(String[] args) throws IOException
    {
    Reader sc=new Reader();
    long n=sc.nextLong();
    long m=sc.nextLong();
    long min=-1;
    long req;
    req=(long) Math.ceil((n)/(2.0));
    long sol1,sol2;
    if(m>=req)
    {
        sol1=0;
    }
    else
    {
        if(n%2==0)
         sol1=(((n/2)-m)*2);
        else
         sol1=(((n/2)-m)*2+1);
    }
    long l=1;
    long r=n;
    long cn=0;
    while(l<=r)
    {
        long mid=(l+r)/2;
        //System.out.println(cn);
        if(((mid)*(mid-1))/2>m)
        r=mid-1;
        else
        {
            cn=mid;
            l=mid+1;
        }
    }
    //System.out.println(cn);
    if((cn*(cn-1))/2==m)
    sol2=n-cn;
    else
    sol2=n-cn-1;
    if(m==0)
    sol2=n;
    System.out.println(sol1+" "+sol2);

    }

	// _________________________TEMPLATE_____________________________________________________________

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

	// static class comp implements Comparator<pair> {
	//
	// @Override
	// public int compare(pair o1, pair o2) {
	// return o2.b - o1.b;
	// }
	//
	// }

	static class pair implements Comparable<pair> {
		int min;
		int max;
		int ans;

		pair(int a, int b) {
			min = a;
			max = b;
		}

		@Override
		public int compareTo(pair o) {

			return (int) (this.min - o.max);

		}
	}

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

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[100000 + 1]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

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

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		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 int[] nextIntArray(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

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

		public int[][] nextInt2DArray(int m, int n) throws IOException {
			int[][] arr = new int[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}

	}

}


import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int count = 0;
        HashMap<Integer,Integer> home = new HashMap<>();
        HashMap<Integer,Integer> guest= new HashMap<>();
        while (n > 0){
            int j = input.nextInt();
            int k = input.nextInt();
            home.put(j, home.getOrDefault(j, 0) + 1);
            guest.put(k, guest.getOrDefault(k, 0) + 1);
            n--;
        }
        for (Map.Entry<Integer,Integer> entry: home.entrySet()){
            count += entry.getValue() * guest.getOrDefault(entry.getKey(), 0);
        }

        System.out.println(count);
        input.close();
    }
}


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

public class A
{

	FastScanner in;
	PrintWriter out;
	int i = 0, j = 0;

	void solve() {
		/**************START**************/
		int sol1 = 0, sol2 = 0, sol3 = 0;
		int n = in.nextInt();
		int min1 = in.nextInt(), max1 = in.nextInt(), min2 = in.nextInt(), max2 = in.nextInt(), min3 = in.nextInt(), max3 = in.nextInt();
		n -= (min1+min2+min3);
		max1 -= min1;
		max2 -= min2;
		max3 -= min3;
		if (max1 >= n)
		{
			sol1 = min1+n;
			sol2 = min2;
			sol3 = min3;
		}
		else
		{
			sol1 = min1 + max1;
			n -= max1;
			if (max2 >= n)
			{
				sol2 = min2 + n;
				sol3 = min3;
			}
			else
			{
				sol2 = min2 + max2;
				n -= max2;
				if (max3 >= n)
				{
					sol3 = min3 + n;
				}
				else
				{
					sol3 = min3 + max3;
				}
			}
		}
		out.println(sol1 + " " + sol2 + " " + sol3);

		/***************END***************/
	}

	public static void main(String[] args) {
		new A().runIO();
	}

	void runIO() {
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

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


/**
 * Created by Rukshar Alam on 10/12/2019.
 */

import  java.util.*;
public class Coins1061A {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();int s = input.nextInt();

        if(s<=n){
            System.out.println("1");
        }
        else{
            int coins = s/n;
            if(s%n != 0)
                coins += 1;
            System.out.println(coins);
        }

    }
}


import javax.sound.midi.SysexMessage;
import java.util.Scanner;

public class Solution {
    public static void main ( String [] args ){
        Scanner s = new Scanner(System.in);
        int i=0,j=0;
        char[][] matrix = new char[4][4];
        for( i = 0 ;i < 4 ; i++){
            String ip = s.nextLine();
            for( j = 0 ; j < 4 ; j++){
                matrix[i][j]= ip.charAt(j);
            }
        }
        boolean ans=false;
        for( i = 0; i < 3 ; i++){
            int count=0;
            for(j=0;j<3;j++){
                count=0;
                if(matrix[i][j]=='#'){
                    count+=1;
                }
                if(matrix[i][j+1]=='#'){
                    count+=1;
                }
                if(matrix[i+1][j]=='#'){
                    count+=1;
                }
                if(matrix[i+1][j+1]=='#'){
                    count+=1;
                }
                if(count>=3){
                    ans=true;
                    break;
                }
                else{
                    count=0;
                    if(matrix[i][j]=='.'){
                        count+=1;
                    }
                    if(matrix[i][j+1]=='.'){
                        count+=1;
                    }
                    if(matrix[i+1][j]=='.'){
                        count+=1;
                    }
                    if(matrix[i+1][j+1]=='.'){
                        count+=1;
                    }
                    if(count>=3){
                        ans=true;
                        break;
                    }
                }
            }
        }
        if(ans == true){
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
}


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

public class Moda {

    public static long abs(long a) {
        if(a < 0) a = -a;
        return a;
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        x %= 360;
        x = -x;
        if(x < 0)
            x += 360;
        int best = 360, k = -1;
        if (Math.min(x, 360 - x) < best) {
            best = (int) Math.min(x, 360 - x);
            k = 0;
        }
        for (int i = 1; i <= 3; ++i) {
            x += 90;
            x %= 360;
            if(Math.min(x, 360 - x) < best) {
                best = (int) Math.min(x, 360 - x);
                k = i;
            }
        }
        System.out.printf("%d\n", k);
    }
}


import java.util.*;
import java.io.*;
public class sol
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int put=1,totalcandies=0,count=0;
		while(n-->0)
		{
		    if(totalcandies>k)
		    {
		        totalcandies--;count++;
		    }
		    else
		    {
		        totalcandies += put;
		        put++;
		    }
		}
		System.out.println(count);
    }
}


 import java.util.Scanner;

public class football {
	public static String buscar(String n){
		String u="1111111";
		String c="0000000";
		for (int i = 0; i < n.length()-6; i++) {
			String temp=n.substring(i, i+7);
			if(temp.equals(u)||temp.equals(c))
				return "YES";
		}
		return "NO";
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String n=sc.next();
		System.out.println(buscar(n));
	}
}


import java.util.Scanner;
/**
 *
 * @author Bug
 */
public class PS {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int a;
        Scanner scn = new Scanner (System.in);
         a = scn.nextInt();

        if (a>2 && a< 101 && (a%2) ==0) {
            System.out.println("YES");

        }else{
            System.out.println("NO");
        }
    }

}


import java.util.*;

public class Main {
		public static void main(String[] args)
		{
			int ans=0,K;boolean flag=false;
			int i,temp,j,k,L;String s;
			Scanner cin =new Scanner(System.in);
			s=cin.nextLine();
			K=cin.nextInt();
			for(i=1;i<=K;i++)
				s+='*';
			for(i=0;i<s.length();i++)
				for(j=i;j<s.length();j++)
				{
					if((j-i)%2==0)
						continue;
					temp=i+j;flag=false;
					L=(j-i+1)/2;
					for(k=i;k<=temp/2;k++)
					{
						if(s.charAt(k)==s.charAt(k+L)||s.charAt(k)=='*'||s.charAt(k+L)=='*')
							continue;
						flag=true;break;
					}
					if(flag==false)
					{
						if(j-i+1>ans)
							ans=j-i+1;
					}
				}
			System.out.printf("%d\n",ans);
		}
}


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

public class CF_919_B_PERFECT_NUMBER {

	static boolean isPerfect(int x)
	{
		int sum = 0;
		int temp = x;
		while(temp!=0)
		{
			sum+= temp%10;
			temp/=10;
		}

		return sum == 10;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int i = 0;
		int num = 18;
		while(i<k)
		{
			num++;
			if(isPerfect(num))
				i++;

		}
		System.out.println(num);

	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));

		}

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

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

		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 long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}

}


import java.util.Scanner;

/**
 *
 * @author 1
 */
public class JavaApplication14 {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws Exception{
        new JavaApplication14().run();
    }
    public class Calc implements Runnable{
        public Calc (int x, int y){
            this.x = x;
            this.y = y;
        }
        public void run(){
            try{
                Thread.sleep(10);
            }catch(Exception e){}
            boolean flag;
            int res = 0;
            for(int i=x; i<y; i++){
                flag = true;
                for(int j=2; j*j<=i; j++){
                    if(i%j == 0){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    res = i;
                }
            }
        }
        public int x;
        public int y;
    }

    void run(){
        int n,m,a;
        Scanner in = new Scanner(System.in);
        n=in.nextInt();
        m=in.nextInt();
        a=in.nextInt();
        n = n/a+((n%a>0)?1:0);
        m = m/a+((m%a>0)?1:0);
        System.out.println(((long)n)*((long)m));
        n = 8;
        m = 3000000/n;
        Calc cl[] = new Calc[n];
        Thread t[] = new Thread[n];
         for(int i=0; i<n; i++){
            cl[i] = new Calc(i*m, (i+1)*m);
            t[i] = new Thread(cl[i]);
        }
        for(int i=0; i<n; i++){
            t[i].start();
        }
        try{
            Thread.sleep(1200);
        }catch(Exception e){}
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=0; i<n; i++){
                if(t[i].getState() != Thread.State.TERMINATED){
                    flag = true;
                    try{
                        Thread.sleep(30);
                    }catch(Exception e){}
                    break;
                }
            }
        }
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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

public class Main {

    BufferedReader reader;
    StringTokenizer token;

    int boy;
    int girl;
    int pick;

    BigInteger[] bg = new BigInteger[32];
    public static void main(String[] args) throws IOException {
        Main ob = new Main();
        ob.run();
        System.exit(0);
    }

    public void run() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        token = new StringTokenizer("");
        gen();
        boy = nextInt();
        girl = nextInt();
        pick = nextInt();

        //System.out.println("IN : "+boy+" "+girl+" "+pick);
        BigInteger retval = BigInteger.ZERO;

        for(int nb=4; nb<=boy;++nb ){
            int ng = pick-nb;
            if( ng>=1 && ng <= girl){
                BigInteger tmp = NcR(boy,nb).multiply( NcR(girl,ng) );
                //System.out.println(nb+" "+tmp);
                retval = retval.add(tmp);
            }
        }

        System.out.println(retval);

    }
    public BigInteger NcR(int N, int R){
        BigInteger up = bg[N];
        BigInteger dn = bg[R].multiply( bg[N-R] );
        return up.divide(dn);
    }

    public void gen() throws IOException{
        bg[0] = BigInteger.ONE;
        for(int i=1;i<=30;++i){
            bg[i] = bg[i-1].multiply( BigInteger.valueOf( (long)i) );
        }
    }

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

    String nextToken() throws IOException {
        while (token == null || !token.hasMoreTokens()) {
            String line = reader.readLine();
            token = new StringTokenizer(line);
        }
        return token.nextToken();
    }
}


import java.util.*;

public class C {
	private static Scanner in;

	class State {
		String s;
		int c;

		public State(String s, int c) {
			this.s = s;
			this.c = c;
		}

		@Override
		public int hashCode() {
			return 13 * s.hashCode() + c;
		}

		@Override
		public boolean equals(Object obj) {
			State that = (State) obj;
			return s.equals(that.s) && c == that.c;
		}

		boolean isTerminal() {
			return s.length() == c;
		}

		State step(char n) {
			int c1 = c;
			String ss = s + n;
			for (;;) {
				int cbest = c1;
				for (String d : dna) {
					for (int i = 0; i <= c1; i++) {
						if (ss.substring(i).startsWith(d)) {
							cbest = Math.max(cbest, i + d.length());
						}
					}
				}
				if (cbest == c1) {
					break;
				}
				c1 = cbest;
			}
			loop:
			for (;;) {
				for (String d : dna) {
					if (d.startsWith(ss)) {
						break loop;
					}
				}
				ss = ss.substring(1);
				c1--;
			}
			if (c1 < 0) {
				return null;
			}
			return new State(ss, c1);
		}
	}

	String[] dna;
	HashMap<State, Integer> map = new HashMap<State, Integer>();
	int[][] nxt = new int[2000][4];
	boolean[] trm = new boolean[2000];
	char[] ns = new char[]{'A', 'C', 'G', 'T'};

	public void run() {
		int n = in.nextInt();
		int m = in.nextInt();
		dna = new String[m];
		for (int i = 0; i < m; i++) {
			dna[i] = in.next();
		}
		State s0 = new State("", 0);
		dfs(s0);
		int k = map.size();
		int[][] a = new int[n + 1][k];
		a[0][0] = 1;
		for (int len = 0; len < n; len++) {
			for (int s = 0; s < k; s++) {
				int aa = a[len][s];
				if (aa == 0) {
					continue;
				}
				for (int i = 0; i < 4; i++) {
					int t = nxt[s][i];
					if (t < 0) {
						continue;
					}
					a[len + 1][t] = add(a[len + 1][t], aa);
				}
			}
		}
		int ans = 0;
		for (int s = 0; s < k; s++) {
			if (trm[s]) {
				ans = add(ans, a[n][s]);
			}
		}
		System.out.println(ans);
	}

	final int MOD = 1000000009;

	private int add(int x, int y) {
		x += y;
		if (x >= MOD) {
			x -= MOD;
		}
		return x;
	}

	private void dfs(State st) {
		if (map.containsKey(st)) {
			return;
		}
		int v = map.size();
		map.put(st, v);
		trm[v] = st.isTerminal();
		for (int i = 0; i < 4; i++) {
			State u = st.step(ns[i]);
			if (u == null) {
				nxt[v][i] = -1;
				continue;
			}
			dfs(u);
			nxt[v][i] = map.get(u);
		}
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new C().run();
		in.close();
	}
}


import java.util.*;
public final class code
{
    static boolean lucky(int n)
    {
        while(n>0)
        {
          int  d=n%10;
            if(d!=4 && d!=7)
            return false;
            n/=10;
        }
        return true;
    }
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int n=0;
        if(sc.hasNextInt())
        {
            n=sc.nextInt();
        }
        boolean flag=lucky(n);
        if(!flag)
        {
            for(int i=1;i<n;i++)
            {
                if(lucky(i) && n%i==0 )
                {
                    flag=true;
                }
            }
        }
        if(flag)
        System.out.println("YES");
        else
        System.out.println("NO");
    }
}


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

public class codeForces {
	public static void main(String [] args) throws Exception{
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		int [][] white = new int[64][2];
		int [][] black = new int[64][2];
		int countWhite = 0;
		int countBlack = 0;
		StringTokenizer st;
		for(int x = 1; x <= 8; x++){
			st = new StringTokenizer(f.readLine());
			String tempy = st.nextToken();
			for(int y = 1; y <=8;y++){
				char temp = tempy.charAt(y - 1);
				if(temp == 'W'){
					white[countWhite][0] = x;
					white[countWhite][1] = y;
					countWhite++;
				}
				else if(temp == 'B'){
					black[countBlack][0] = x;
					black[countBlack][1] = y;
					countBlack++;
				}
			}
		}
		boolean go = false;
		int blackMin = Integer.MAX_VALUE;
		int whiteMin = Integer.MAX_VALUE;
		for(int x = 0; x < countWhite; x++){
			go = true;
			for(int y = 0; y < countBlack; y++){
				if(white[x][1] == black[y][1] && white[x][0] > black[y][0]){
					go = false;
					break;
				}
			}
			if(go && Math.abs(1 - white[x][0]) < whiteMin)
				whiteMin = Math.abs(1 - white[x][0]);
		}
		for(int x = 0; x < countBlack; x++){
			go = true;
			for(int y = 0; y < countWhite; y++){
				if(black[x][1] == white[y][1] && black[x][0] < white[y][0]){
					go = false;
					break;
				}
			}
			if(go && 8 - black[x][0] < blackMin){
				blackMin = 8 - black[x][0];
			}
		}
		if(whiteMin == blackMin || whiteMin < blackMin)
			System.out.print("A");
		else
			System.out.print("B ");
	}
}


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

public class CFC {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;

    void solve() throws IOException {
        int n = 24;
        int[] arr = nextIntArr(n);
        int[][] idx = {{1, 3, 5, 7, 9, 11, 22, 24},
        {2, 4, 6, 8, 10, 12, 21, 23},
        {13, 14, 5, 6, 17, 18, 21, 22},
        {15, 16, 7, 8, 19, 20, 23, 24},
        {1, 2, 18, 20, 12, 11, 15, 13},
        {3, 4, 17, 19, 10, 9, 16, 14}};

        for (int[] cand : idx) {
            int[] candArr = Arrays.copyOf(cand, cand.length);
            int[] fix = Arrays.copyOf(arr, arr.length);

            int[] left = shiftLeft(candArr);
            boolean flag = check(fix, candArr, left);
            if (flag) {
                out("YES");
                return;
            }

            int[] right = shiftRight(candArr);
            flag = check(fix, candArr, right);
            if (flag) {
                out("YES");
                return;
            }
        }

        out("NO");
    }

    boolean check(int[] mat, int[] old, int[] index) {
//        for (int i = 0; i < old.length; i++) {
//            swap(mat, old[i] - 1, index[i] - 1);
//        }

        int[] newMat = Arrays.copyOf(mat, mat.length);
        for (int i = 0; i < old.length; i++) {
            newMat[index[i] - 1] = mat[old[i] - 1];
        }
        return isValid(newMat);
    }

    int[] shiftRight(int[] ind) {
        int[] res = new int[8];
        for (int i = 2; i < 8; i++) {
            res[i] = ind[i - 2];
        }

        res[0] = ind[6];
        res[1] = ind[7];
        return res;
    }

    int[] shiftLeft(int[] ind) {
        int[] res = new int[8];
        for (int i = 0; i < 6; i++) {
            res[i] = ind[i + 2];
        }
        res[6] = ind[0];
        res[7] = ind[1];
        return res;
    }

    boolean isValid(int[] arr) {
        for (int i = 0; i < 6; i++) {
            int cnt1 = arr[4 * i];
            for (int j = 1; j < 4; j++) {
                if (arr[4 * i + j] != cnt1) {
                    return false;
                }
            }
        }

        return true;
    }

    void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFC() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFC();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1174E
   {
      static long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         long[][] dp = new long[20][2];
         base(dp, N);
         cnt = new long[20][2];
         for(int curr=0; (1<<curr) <= N; curr++)
            for(int b=1; b <= 3; b+=2)
            {
               int temp = (1<<curr)*b;
               cnt[curr][Math.max(b-2, 0)] = N/temp;
            }
         //iterative sad
         for(int i=2; i <= N; i++)
         {
            long[][] newdp = new long[20][2];
            for(int a=19; a >= 0; a--)
               for(int b=1; b >= 0; b--)
               {
                  long res = 0L;
                  if(cnt[a][b]-i >= 0)
                     res = (dp[a][b]*(cnt[a][b]-i+1+MOD))%MOD;
                  if(a+1 < 20)
                  {
                     res += (dp[a+1][b]*(cnt[a][b]-cnt[a+1][b]))%MOD;
                     if(res >= MOD)
                        res -= MOD;
                  }
                  if(b == 0)
                  {
                     res += (dp[a][1]*(cnt[a][0]-cnt[a][1]))%MOD;
                     if(res >= MOD)
                        res -= MOD;
                  }
                  newdp[a][b] = res;
               }
            dp = newdp;
         }
         System.out.println(dp[0][0]);
      }
      static long[][] cnt;
      public static void base(long[][] dp, int N)
      {
         int curr = 1;
         while((1<<curr) <= N)
            curr++;
         curr--;
         dp[curr][0] = 1L;
         int oth = 1<<(curr-1);
         oth *= 3;
         if(oth <= N)
            dp[curr-1][1] = 1L;
      }
   }


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

/**
 * @author Don Li
 */
public class Splits {
    void solve() {
        int n = in.nextInt();
        out.println((n >> 1) + 1);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Splits().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

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

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

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


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();
    int b = s.nextInt();
    int t = a;
    while (a >= b) { int r = a % b; a = a / b; t += a; a += r; }
    System.out.println(t);
  }
}


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

public class A {
    public static void solution(BufferedReader reader, PrintWriter out)
            throws IOException {
        In in = new In(reader);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
        int cnt = 0;
        int n = a - 1;
        for (int i = 0; i < Math.min(b, c); i++) {
            n++;
            cnt += n * 2;
        }
        cnt += n * (Math.abs(b - c) - 1);
        out.println(cnt);
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(
                new OutputStreamWriter(System.out)));
        solution(reader, out);
        out.close();
    }

    protected static class In {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public In(BufferedReader reader) {
            this.reader = reader;
        }

        public String next() throws IOException {
            while (!tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

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

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

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


import java.util.Scanner;
public class JavaApplication71 {
    public static void main(String[] args) {
        //helpful mathe
        Scanner input =new Scanner(System.in);
        String s=input.next();
        int c1=0 ;int c2=0 ;int c3=0;
        String result="";
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='1'){
                c1++;
            }else if(s.charAt(i)=='2'){
                c2++;
            }else if(s.charAt(i)=='3'){
                c3++;
            }
            }
                for(int j=0;j<c1;j++){
                    result=result+"1+";
                }
                for(int j=0;j<c2;j++){
                    result=result+"2+";
        }
                for(int j=0;j<c3;j++){
                    result=result+"3+";
    }
                result=result.substring(0, s.length());
                System.out.println(result);

    }
}


import java.lang.*;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Mido
 */
public class Test {

    /**
     * @param args the command
     */
    public static int weight(char c)
    {
        c=Character.toLowerCase(c);
        switch(c)
        {
            case 'q': return 9;
            case 'r': return 5;
            case 'b': return 3;
            case 'n': return 3;
            case 'p': return 1;
            case 'k':
            break;
        }
        return 0;
    }
    public static void main(String[] args) {
        int j,i,w,b;
        String ans;
        char c;
        String []a=new String[8];
        Scanner sc=new Scanner(System.in);
       w=b=0;
       for(i=0;i<8;i++) a[i]=sc.next();
       for(i=0;i<8;i++)
       {
           for(j=0;j<8;j++)
           {
               c=a[i].charAt(j);

               if(c!='.')
               {
                   if(c>='a'&&c<='z')b+=weight(c);
                   else w+=weight(c);
               }
           }
       }
       if(w>b)System.out.println("White");
       else if(w<b)System.out.println("Black");
       else System.out.println("Draw");
    }

}


import java.util.Scanner;

/**
 * https://codeforces.com/contest/1081/problem/A
 *
 */
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long n = Long.parseLong(s.nextLine());
		long x = n - 1;
		while (true) {
			if (n < 2 || x < 2) {
				break;
			}
			if (n % x != 0) {
				n -= x;
			}
			x--;
		}
		System.out.println(n);
	}
}


import java.util.*;
public class Q1064A
{
    public static void main(String[] args)
    {
        int a[],max=0;
        Scanner sc=new Scanner(System.in);
        a=new int[3];
        for(int i=0;i<3;i++)
        {
            a[i]=sc.nextInt();
        }
        for(int i=0;i<2;i++)
        {
            if(a[i]>a[i+1])
            {
                max=a[i+1];
                a[i+1]=a[i];
                a[i]=max;
            }
        }
        if(a[2]<(a[1]+a[0]))
        {
            System.out.println(0);
        }
        else
        {
            System.out.println((a[2]-(a[1]+a[0])+1));
        }
        sc.close();
    }
}


import java.util.*;

public class Main{

        public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        HashMap<Integer,Integer> mp=new HashMap<Integer,Integer>();
        while(mp.get(n)==null)
        {
            mp.put(n, 1);
            n=n+1;
            while(n%10==0) n/=10;
        }
        System.out.println(mp.size()) ;

    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskB2 {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int m = in.readInt();

        int[] dp = new int[n + 1];
        dp[0] = dp[1] = 1;

        for (int i = 2; i <= n; i++) {
            for (int j = 0; j < i; j++) {
                dp[i] += dp[j];
            }
        }

        int[] a = new int[n];
        boolean[] used = new boolean[n + 1];

        int add = 0;
        int last = 0;
        for (int i = 0; i < n; i++) {
            for (int j = last + 1; j <= n; j++) {
                if(used[j]) continue;

                int grt = 0;
                for (int k = j + 1; k <= n; k++) {
                    if (!used[k])   grt++;
                }
                if (add + dp[grt] >= m) {
                    a[i] = j;
                    used[j] = true;
                    last = j;
                    break;
                } else {
                    add += dp[grt];
                }
            }
        }

        for (int i = n - 1; i >= 0; i--) {
            if (a[i] == 0) {
                for (int j = 1; j <= n; j++) {
                    if (!used[j]) {
                        a[i] = j;
                        used[j] = true;
                        break;
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            out.print(a[i] + " ");
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

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

    public 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++];
    }

    public int readInt() {
        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;
    }

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

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

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

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void close() {
        writer.close();
    }

}


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

/**
 * Created by Alvin on 5/24/2016.
 */

public class Codeforces_round_335_div_2_MagicSpheres {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int x = input.nextInt();
        int y = input.nextInt();
        int z = input.nextInt();
        int remainBalls = 0;
        if(a - x > 0) {
            remainBalls += (a - x) / 2;
        }

        if(b - y > 0) {
            remainBalls += (b - y) / 2;
        }
        if(c - z > 0) {
            remainBalls += (c - z) / 2;
        }
        if(a < x) {
            remainBalls -= (x - a);
        }
        if(b < y) {
            remainBalls -= (y - b);
        }
        if(c < z) {
            remainBalls -= (z - c);
        }
        if(remainBalls >= 0) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        int k=sc.nextInt();
        int i=0;
        while(i!=k){
            if(n%10==0){
                while(n%10==0&&i!=k){
                    n=n/10;
                    i=i+1;
                }
            }
            else{
                while(n%10!=0&&n>0&&i!=k){
                    n=n-1;
                    i=i+1;
                }
            }
        }
        System.out.println(n);
    }
}


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

public class RaceTime2 {
	public static boolean clock (int h, int m, int s, int t1, int t2) {
		int t1_s = t1 * 5;
		if (t1_s >= 60)
			t1_s -= 60;
		boolean solution_s = false;
		int t2_s = t2 * 5;
		if (t2_s >= 60)
			t2_s -= 60;
		while (t1_s != s) {
			if (t1_s == t2_s) {
				solution_s = true;
				break;
			}
			t1_s++;
			if (t1_s > 59)
				t1_s -= 60;
		}
		if (!solution_s)
			return false;

		double t1_m = (double)t1 * (double)5;
		if (t1_m >= 60)
			t1_m -= 60;
		double m1 = (double)m;
		boolean solution_m = false;
		if (s > 0)
			m1 += 0.5;
		if (m1 >= 60)
			m1 -= 60;
		double t2_m = (double)t2 * (double)5;
		if (t2_m >= 60)
			t2_m -= 60;
		while (t1_m != (double)m1) {
			if (t1_m == t2_m) {
				solution_m = true;
				break;
			}
			t1_m += 0.5;
			if (t1_m >= 60)
				t1_m -= 60;
		}
		if (!solution_m)
			return false;

		double t1_h = (double)t1;
		double h1 = (double)h;
                boolean solution_h = false;
                if (m > 0 || s > 0)
                        h1 += 0.5;
		if (h1 > 12)
			h1 -= 12;
                while (t1_h != (double)h1) {
                        if (t1_h == (double)t2) {
                                solution_h = true;
                                break;
                        }
                        t1_h += 0.5;
                        if (t1_h > 12)
                                t1_h -= 12;
                }
                if (!solution_h)
                        return false;
		return true;
	}

	public static boolean anti (int h, int m, int s, int t1, int t2) {
                int t1_s = t1 * 5;
		if (t1_s >= 60)
			t1_s -= 60;
                boolean solution_s = false;
		int t2_s = t2 * 5;
		if (t2_s >= 60)
			t2_s -= 60;
                while (t1_s != s) {
                        if (t1_s == t2_s) {
                                solution_s = true;
                                break;
                        }
                        t1_s--;
                        if (t1_s < 0)
                                t1_s += 60;
                }
                if (!solution_s)
                        return false;

                double t1_m = (double)t1 * (double)5;
		if (t1_m >= 60)
			t1_m -= 60;
                double m1 = (double)m;
                boolean solution_m = false;
                if (s > 0)
                        m1 += 0.5;
                if (m1 >= 60)
                        m1 -= 60;
		double t2_m = (double)t2 * (double)5;
		if (t2_m >= 60)
			t2_m -= 60;
                while (t1_m != (double)m1) {
                        if (t1_m == t2_m) {
                                solution_m = true;
                                break;
                        }
                        t1_m -= 0.5;
                        if (t1_m < 0)
                                t1_m += 60;
                }
                if (!solution_m)
                        return false;

                double t1_h = (double)t1;
                double h1 = (double)h;
                boolean solution_h = false;
                if (m > 0 || s > 0)
                        h1 += 0.5;
                if (h1 > 12)
                        h1 -= 12;
                while (t1_h != (double)h1) {
                        if (t1_h == (double)t2) {
	                        solution_h = true;
                                break;
                        }
                        t1_h -= 0.5;
                        if (t1_h < 0.5)
                                t1_h += 12;
                }
                if (!solution_h)
                        return false;
                return true;
        }

	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner (System.in);
		int h = sc.nextInt();
		int m = sc.nextInt();
		int s = sc.nextInt();
		int t1 = sc.nextInt();
		int t2 = sc.nextInt();
		if (clock (h, m, s, t1, t2) || anti (h, m, s, t1, t2)) {
			System.out.println ("YES");
		} else System.out.println ("NO");
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int k, c = 0, sum = 0, summ = 0;
        int[] A = new int[12];

        Scanner s = new Scanner(System.in);
        k = s.nextInt();
        s.nextLine();
        for (int i = 0; i < 12; i++) {
            A[i] = s.nextInt();
        }
        Arrays.sort(A);
        for (int x : A) {
            summ += x;
        }
        if (summ < k)
            System.out.println(-1);
        else {
            for (int i = 11; i >= 0; i--) {
                if (sum < k) {
                    sum += A[i];
                    c++;
                    if(sum==k)
                    {
                        System.out.println(c);
                        break;
                    }
                } else {
                    System.out.println(c);
                    break;
                }
            }
        }
    }
}


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

/* Name of the class has to be "Main" only if the class is public. */
  public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s =new Scanner(System.in);
		int w1=s.nextInt();
		int h1=s.nextInt();
		int w2=s.nextInt();
		int h2=s.nextInt();
		int count=w1*2+(h1+h2)*2+4;
		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.util.stream.*;
import java.util.stream.Collectors.*;

import static java.util.stream.Collectors.*;

public class codeforces {
    public static void main(String[] args) throws Exception {
        try {
             InputStreamReader isr = new InputStreamReader(System.in);
             BufferedReader br = new BufferedReader(isr);
             int len=Integer.parseInt(br.readLine());
             String inp=br.readLine();
             int count=0;
             StringBuffer naya = new StringBuffer(inp);
             while(naya.indexOf("xxx")!=-1){
                 int ndx=naya.indexOf("xxx");
                 naya.deleteCharAt(ndx);
                 count++;
             }
             System.out.println(count);
       } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


import java.util.Scanner;

public class PlateGame {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int r = in.nextInt();
        if (Math.min(a, b) < 2 * r) {
            System.out.println("Second");
        } else {
            System.out.println("First");
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;
public class JavaApplication18 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double r=sc.nextInt();
double x=sc.nextInt();
double y=sc.nextInt();
double x1=sc.nextInt();
double y1=sc.nextInt();

 x=Math.abs(x-x1);
 y=Math.abs(y-y1);
double ans=Math.sqrt((x*x+y*y))/(2*r);

System.out.println((int)Math.ceil((ans)));

}

}


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

public class Mainn {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int x = scn.nextInt(), y = scn.nextInt(), mod = (int) 1e9 + 7;
		if (y % x != 0) {
			out.println(0);
			return;
		}
		int k = y / x;

		HashMap<Integer, Long> map = new HashMap<>();
		map.put(1, 1L);

		out.println(func(k, map, mod));
	}

	long func(int k, HashMap<Integer, Long> map, int mod) {
		if (map.containsKey(k)) {
			return map.get(k);
		}
		long rv = 1;
		for (int i = 2; i * i <= k; i++) {
			if (k % i != 0) {
				continue;
			}
			rv += func(i, map, mod);
			if (i * i != k) {
				rv += func(k / i, map, mod);
			}
		}

		rv %= mod;
		rv = (power(2, k - 1, mod) - rv + mod) % mod;
		map.put(k, rv);

		return rv;
	}

	long power(long a, long x, long mod) {
		if (x == 0) {
			return 1;
		}
		long p = power(a, x / 2, mod);
		p *= p;
		p %= mod;
		if (x % 2 == 1) {
			p *= a;
			p %= mod;
		}
		return p;
	}

	void run() throws Exception {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		long time = System.currentTimeMillis();
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

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

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());

		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		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++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(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);
		}

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

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

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

		int nextInt() {
			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();
			}
		}

		long nextLong() {
			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();
			}
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}


import java.io.*;
import java.util.*;
public class Main{
     public static void main(String []args)throws IOException{
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
         //int t=Integer.parseInt(br.readLine());
         //while(t-- >0){
			//int n =Integer.parseInt(br.readLine());
			String inp[]=br.readLine().split(" ");
			int m=Integer.parseInt(inp[0]),s=Integer.parseInt(inp[1]);
			if(s==0 && m==1){
			    bw.write("0 0");
			}
			else if(s==0 || s > 9*m){
			    bw.write("-1 -1");
			}
			else{
			    String max="",min="";
			    int temp=s;
			    int i=0;
			    for(;i<m;i++){
			        if(temp>0){
			            max+=Integer.toString(Math.min(9,temp));
			            temp=temp-Math.min(9,temp);
			        }
			        else{
			            max+="0";
			        }
			    }

			    temp=s;
			    for(i=m-1;i>=0;i--){
			        if(temp>9){
			            min="9"+min;
			            temp=temp-9;
			        }
			        else if(i==0){
			            min=Integer.toString(temp)+min;
			        }
			        else if(temp<10 && temp!=1){
			            min=Integer.toString(temp-1)+min;
			            temp=1;
			        }
			        else{
			            min="0"+min;
			        }
			    }
			    bw.write(min+" "+max);
			}
         //}
         bw.flush();
     }
}