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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        String numbers = sc.nextLine();
        String av = sc.nextLine();
        int totalCount = 0;
        while(true) {
            int count = 0;
            List<String> items = new ArrayList<>();
            for(int i = 0; i < av.length(); i++) {
                items.add(String.valueOf(av.charAt(i)));
            }

            for(int i = 0; i < numbers.length(); i++) {
                boolean isItemUsed = false;
                for(int j = 0; j < items.size(); j++) {
                    if((items.get(j).equals(String.valueOf(numbers.charAt(i))) || isItems2or5(String.valueOf(numbers.charAt(i)), items.get(j)) || isItems6or9(String.valueOf(numbers.charAt(i)), items.get(j))) && !isItemUsed) {
                        items.set(j, "");
                        count++;
                        isItemUsed = true;
                    }
                }
            }

            if(count != numbers.length()) {
                break;
            }

            totalCount++;
            av = "";
            for(int i = 0; i < items.size(); i++) {
                if(items.get(i) != null) {
                    av += items.get(i);
                }
            }
        }

        pw.println(totalCount);
        pw.close();
        sc.close();
    }

    static boolean isItems2or5(String number, String listItem) {
        return ("2".equals(number) && "5".equals(listItem)) || ("5".equals(number) && "2".equals(listItem));
    }

    static boolean isItems6or9(String number, String listItem) {
        return ("6".equals(number) && "9".equals(listItem)) || ("9".equals(number) && "6".equals(listItem));
    }
}


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

public class R191_Test8_B //Name: Sheldon and Ice Pieces
{
	public static void main(String[] args) {
		Scanner      in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		solve(in, out);
		out.close();
		in.close();
	}

	public static void solve(Scanner in, PrintWriter out)
	{
		int n = in.nextInt();
		int k = in.nextInt();

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

		String s = in.next();

		StringBuilder sb = new StringBuilder(s + k);
		sb.append("\r\n");

		out.println(sb);
	}
}


package task;

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

public class Cubs {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String number = null;
		String digits = null;

		BufferedReader bufferRead = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			number = bufferRead.readLine();
			digits = bufferRead.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}

		int size = number.length();
		int[] countsInDigits = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		int[] countsInNumber = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

		for (int k = 0; k <= 9; k++) {
			for (int i = 0; i < digits.length(); i++) {
				if (Character.getNumericValue(digits.charAt(i)) == k) {
					countsInDigits[k]++;
				}
			}
		}

		for (int k = 0; k <= 9; k++) {
			for (int i = 0; i < number.length(); i++) {
				if (Character.getNumericValue(number.charAt(i)) == k) {
					countsInNumber[k]++;
				}
			}
		}

		int max = 34;
		for (int i = 0; i <= 9; i++) {
			if (countsInNumber[i] > 0) {
				int y = 0;
				if (i != 2 && i != 5 && i != 6 && i != 9) {
					y = countsInDigits[i] / countsInNumber[i];
				} else if (i == 2 || i == 5) {
					y = (countsInDigits[2] + countsInDigits[5])
							/ (countsInNumber[2] + countsInNumber[5]);
				} else if (i == 6 || i == 9) {
					y = (countsInDigits[6] + countsInDigits[9])
							/ (countsInNumber[6] + countsInNumber[9]);
				}
				if(y<max){
					max = y;
				}
			}
		}

		System.out.println(max);

	}
}


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

import java.util.Scanner;

/**
 *
 * @author Lotus
 */
public class B {

    public static void main(String[]args)
    {
        Scanner input = new Scanner (System.in);
        String t  = input.next();
        String ices = input.next();
        int [] counter = new int[9];

            for(int j=0; j<ices.length();j++)
            {

                    if(ices.charAt(j)=='9')
                        counter[6]++;
                    else if(ices.charAt(j)=='5' )
                    {
                         counter[2]++;

                    }
                     else
                    counter[ices.charAt(j)-48]++;

            }
        int count=0;
        int n;
        boolean m=false;
        while(m!=true)
        {
         for(int i=0; i<t.length();i++)
            {

                     if(t.charAt(i)=='9')
                         n=6;

                    else if(t.charAt(i)=='5' )
                    {
                        n=2;

                    }
                     else
                   n=t.charAt(i)-48;

                     counter[n]--;
                   if( counter[n]<0)
                   {
                       m=true;
                       break;

                   }
            }
        if(!m)
         count++;

            }

        System.out.println(count);

    }

}


import java.util.Scanner;

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

		int n = scan.nextInt();
		scan.nextLine();

		String k = scan.nextLine();
		String temp = "";

		for(int i=2; i<=n; i++) {
		    if(n%i == 0) {
		        for(int j=i-1; j>=0; j--) {
		            temp += k.charAt(j);
		        }
		        for(int j=i; j<n; j++) {
		            temp += k.charAt(j);
		        }
		        k = temp;
		        temp = "";
		    }
		}

		System.out.println(k);

	}
}


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

public class Main {

    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        int n = reader.nextInt();
        int a = n;
        int b = a;
        int d = 1;
        String t = reader.next();
        while (d < n) {
            if (n % d == 0) {
                String c = t.substring(0, d);
                String exchange = new StringBuffer(c).reverse().toString();
                t = exchange + t.substring(d);
            }
            d++;
        }
        String[] arr = new String[n / 2];
        String t1 = new StringBuffer(t).reverse().toString();
        System.out.println(t1);
    }

static class InputReader {

    StringTokenizer tokenizer;
    BufferedReader reader;
    String token;
    String temp;

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

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

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

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                if (temp != null) {
                    tokenizer = new StringTokenizer(temp);
                    temp = null;
                } else {
                    tokenizer = new StringTokenizer(reader.readLine());
                }

            } catch (IOException e) {
            }
        }
        return tokenizer.nextToken();
    }

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

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

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


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

public class Main {

    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        int n = reader.nextInt();
        int a = n;
        int b = a;
        int d = 1;
        String t = reader.next();
        while (d < n) {
            if (n % d == 0) {
                String c = t.substring(0, d);
                String exchange = new StringBuffer(c).reverse().toString();
                t = exchange + t.substring(d);
            }
            d++;
        }
        String[] arr = new String[n / 2];
        String t1 = new StringBuffer(t).reverse().toString();
        System.out.println(t1);
    }
}

static class InputReader {

    StringTokenizer tokenizer;
    BufferedReader reader;
    String token;
    String temp;

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

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

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

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                if (temp != null) {
                    tokenizer = new StringTokenizer(temp);
                    temp = null;
                } else {
                    tokenizer = new StringTokenizer(reader.readLine());
                }

            } catch (IOException e) {
            }
        }
        return tokenizer.nextToken();
    }

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

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

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


import java.util.*;
public class file{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
scan.nextLine();
String str=scan.nextLine();
char[] ch=new char[n];
for(int i=0;i<n;i++){
ch[i]=str.charAt(i);
}
for(int j=2;j<n;j++){
if(n%j===0){
for(int k=0,l=j-1;k<j/2;k++,l--){
char temp=ch[k];
ch[k]=ch[l];
ch[l]=temp;

}
}
}
String ans="";
for(int m=n;m>=0;m--){
ans+=ch[m];
}
System.out.println(ans);
}
}


import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class B implements Runnable{

    // SOLUTION!!!
    // HACK ME PLEASE IF YOU CAN!!!
    // PLEASE!!!
    // PLEASE!!!
    // PLEASE!!!

    private final static Random rnd = new Random();
    private final static String fileName = "";

    private final static String ENTER = "+", EXIT = "-";

    private void solve() {
        int n = readInt();
        int m = readInt();

        boolean[] canBeLeader = new boolean[n];
        Arrays.fill(canBeLeader, true);

        class Event {
            boolean enter;
            int index;

            public Event(String type, int index) {
                this.enter = ENTER.equals(type);
                this.index = index;
            }
        }

        Event[] inputEvents = new Event[m];
        for (int i = 0; i < m; ++i) {
            inputEvents[i] = new Event(readString(), readInt() - 1);
        }

        int startMeetingSize = 0;

        Set<Integer> wasBefore = new HashSet<>();

        boolean[] used = new boolean[n];
        for (Event inputEvent : inputEvents) {
            if (!inputEvent.enter && !used[inputEvent.index]) {
                wasBefore.add(inputEvent.index);
            }

            used[inputEvent.index] = true;
        }

        SortedSet<Integer> zeros = new TreeSet<>();

        int meetingSize = wasBefore.size();
        for (Event event : inputEvents) {
            if (event.enter) {
                if (meetingSize != 0) {
                    canBeLeader[event.index] = false;
                } else {
                    zeros.add(event.index);
                }

                ++meetingSize;
            } else {
                --meetingSize;

                if (meetingSize != 0) {
                    canBeLeader[event.index] = false;
                } else {
                    zeros.add(event.index);
                }
            }
        }

        if (zeros.size() > 1) {
            for (int index : zeros) {
                canBeLeader[index] = false;
            }
        } else if (zeros.size() == 1){
            int zeroEnter = zeros.first();

            if (wasBefore.size() > 0 && !wasBefore.contains(zeroEnter)) {
                canBeLeader[zeroEnter] = false;
            }
        }

        List<Integer> possibleLeaders = new ArrayList<>();
        for (int i = 0; i < n; ++i) {
            if (canBeLeader[i]) possibleLeaders.add(i);
        }

        out.println(possibleLeaders.size());
        for (int leader : possibleLeaders) {
            out.print((leader + 1) + " ");
        }
        out.println();
    }

    /////////////////////////////////////////////////////////////////////

    private final static boolean FIRST_INPUT_STRING = false;
    private final static boolean MULTIPLE_TESTS = true;
    private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private final static int MAX_STACK_SIZE = 128;

    private final static boolean OPTIMIZE_READ_NUMBERS = false;

    /////////////////////////////////////////////////////////////////////

    public void run(){
        try{
            timeInit();
            Locale.setDefault(Locale.US);

            init();

            if (ONLINE_JUDGE) {
                solve();
            } else {
                do {
                    try {
                        timeInit();
                        solve();
                        time();

                        out.println();
                    } catch (NumberFormatException e) {
                        break;
                    } catch (NullPointerException e) {
                        if (FIRST_INPUT_STRING) break;
                        else throw e;
                    }
                } while (MULTIPLE_TESTS);
            }

            out.close();
            time();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    /////////////////////////////////////////////////////////////////////

    private BufferedReader in;
    private OutputWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args){
        new Thread(null, new B(), "", MAX_STACK_SIZE * (1L << 20)).start();
    }

    /////////////////////////////////////////////////////////////////////

    private void init() throws FileNotFoundException{
        Locale.setDefault(Locale.US);

        if (ONLINE_JUDGE){
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new OutputWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new OutputWriter(fileName + ".out");
            }
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new OutputWriter("output.txt");
        }
    }

    ////////////////////////////////////////////////////////////////

    private long timeBegin;

    private void timeInit() {
        this.timeBegin = System.currentTimeMillis();
    }

    private void time(){
        long timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    private void debug(Object... objects){
        if (ONLINE_JUDGE){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    /////////////////////////////////////////////////////////////////////

    private String delim = " ";

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private String readString() {
        try {
            while(!tok.hasMoreTokens()){
                tok = new StringTokenizer(readLine());
            }

            return tok.nextToken(delim);
        } catch (NullPointerException e) {
            return null;
        }
    }

    /////////////////////////////////////////////////////////////////

    private final char NOT_A_SYMBOL = '\0';

    private char readChar() {
        try {
            int intValue = in.read();

            if (intValue == -1){
                return NOT_A_SYMBOL;
            }

            return (char) intValue;
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private char[] readCharArray() {
        return readLine().toCharArray();
    }

    private char[][] readCharField(int rowsCount) {
        char[][] field = new char[rowsCount][];
        for (int row = 0; row < rowsCount; ++row) {
            field[row] = readCharArray();
        }

        return field;
    }

    /////////////////////////////////////////////////////////////////

    private long optimizedReadLong() {
        int sign = 1;
        long result = 0;
        boolean started = false;
        while (true) {
            try {
                int j = in.read();
                if (-1 == j) {
                    if (started) return sign * result;
                    throw new NumberFormatException();
                }

                if (j == '-') {
                    if (started) throw new NumberFormatException();
                    sign = -sign;
                }

                if ('0' <= j && j <= '9') {
                    result = result * 10 + j - '0';
                    started = true;
                } else if (started) {
                    return sign * result;
                }
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }
    }

    private int readInt() {

        if (!OPTIMIZE_READ_NUMBERS) {
            return Integer.parseInt(readString());
        } else {
            return (int) optimizedReadLong();
        }
    }

    private int[] readIntArray(int size) {
        int[] array = new int[size];

        for (int index = 0; index < size; ++index){
            array[index] = readInt();
        }

        return array;
    }

    private int[] readSortedIntArray(int size) {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    private int[] readIntArrayWithDecrease(int size) {
        int[] array = readIntArray(size);

        for (int i = 0; i < size; ++i) {
            array[i]--;
        }

        return array;
    }

    ///////////////////////////////////////////////////////////////////

    private int[][] readIntMatrix(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArray(columnsCount);
        }

        return matrix;
    }

    private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);
        }

        return matrix;
    }

    ///////////////////////////////////////////////////////////////////

    private long readLong() {
        if (!OPTIMIZE_READ_NUMBERS) {
            return Long.parseLong(readString());
        } else {
            return optimizedReadLong();
        }
    }

    private long[] readLongArray(int size) {
        long[] array = new long[size];

        for (int index = 0; index < size; ++index){
            array[index] = readLong();
        }

        return array;
    }

    ////////////////////////////////////////////////////////////////////

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

    private double[] readDoubleArray(int size) {
        double[] array = new double[size];

        for (int index = 0; index < size; ++index){
            array[index] = readDouble();
        }

        return array;
    }

    ////////////////////////////////////////////////////////////////////

    private BigInteger readBigInteger() {
        return new BigInteger(readString());
    }

    private BigDecimal readBigDecimal() {
        return new BigDecimal(readString());
    }

    /////////////////////////////////////////////////////////////////////

    private Point readPoint() {
        int x = readInt();
        int y = readInt();
        return new Point(x, y);
    }

    private Point[] readPointArray(int size) {
        Point[] array = new Point[size];

        for (int index = 0; index < size; ++index){
            array[index] = readPoint();
        }

        return array;
    }

    /////////////////////////////////////////////////////////////////////

    @Deprecated
    private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) {
        @SuppressWarnings("unchecked")
        List<Integer>[] graph = new List[vertexNumber];

        for (int index = 0; index < vertexNumber; ++index){
            graph[index] = new ArrayList<>();
        }

        while (edgeNumber-- > 0){
            int from = readInt() - 1;
            int to = readInt() - 1;

            graph[from].add(to);
            graph[to].add(from);
        }

        return graph;
    }

    private static class GraphBuilder {

        final int size;
        final List<Integer>[] edges;

        static GraphBuilder createInstance(int size) {
            List<Integer>[] edges = new List[size];
            for (int v = 0; v < size; ++v) {
                edges[v] = new ArrayList<>();
            }

            return new GraphBuilder(edges);
        }

        private GraphBuilder(List<Integer>[] edges) {
            this.size = edges.length;
            this.edges = edges;
        }

        public void addEdge(int from, int to) {
            addDirectedEdge(from, to);
            addDirectedEdge(to, from);
        }

        public void addDirectedEdge(int from, int to) {
            edges[from].add(to);
        }

        public int[][] build() {
            int[][] graph = new int[size][];
            for (int v = 0; v < size; ++v) {
                List<Integer> vEdges = edges[v];
                graph[v] = castInt(vEdges);
            }

            return graph;
        }
    }

    /////////////////////////////////////////////////////////////////////

    private static class IntIndexPair {

        static Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {

            @Override
            public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return value1 - value2;

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        static Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {

            @Override
            public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return -(value1 - value2);

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        int value, index;

        IntIndexPair(int value, int index) {
            super();
            this.value = value;
            this.index = index;
        }

        int getRealIndex() {
            return index + 1;
        }
    }

    private IntIndexPair[] readIntIndexArray(int size) {
        IntIndexPair[] array = new IntIndexPair[size];

        for (int index = 0; index < size; ++index) {
            array[index] = new IntIndexPair(readInt(), index);
        }

        return array;
    }

    /////////////////////////////////////////////////////////////////////

    private static class OutputWriter extends PrintWriter {

        final int DEFAULT_PRECISION = 12;

        private int precision;
        private String format, formatWithSpace;

        {
            precision = DEFAULT_PRECISION;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        OutputWriter(OutputStream out) {
            super(out);
        }

        OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        int getPrecision() {
            return precision;
        }

        void setPrecision(int precision) {
            precision = max(0, precision);
            this.precision = precision;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        String createFormat(int precision){
            return "%." + precision + "f";
        }

        @Override
        public void print(double d){
            printf(format, d);
        }

        void printWithSpace(double d){
            printf(formatWithSpace, d);
        }

        void printAll(double...d){
            for (int i = 0; i < d.length - 1; ++i){
                printWithSpace(d[i]);
            }

            print(d[d.length - 1]);
        }

        @Override
        public void println(double d){
            printlnAll(d);
        }

        void printlnAll(double... d){
            printAll(d);
            println();
        }
    }

    /////////////////////////////////////////////////////////////////////

    private static class RuntimeIOException extends RuntimeException {

        /**
         *
         */
        private static final long serialVersionUID = -6463830523020118289L;

        RuntimeIOException(Throwable cause) {
            super(cause);
        }
    }

    /////////////////////////////////////////////////////////////////////
    //////////////// Some useful constants and functions ////////////////
    /////////////////////////////////////////////////////////////////////

    private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    private static final int[][] steps8 = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1},
            {-1, -1}, {1, 1}, {1, -1}, {-1, 1}
    };

    private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {
        return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);
    }

    private static boolean checkIndex(int index, int lim){
        return (0 <= index && index < lim);
    }

    /////////////////////////////////////////////////////////////////////

    private static boolean checkBit(int mask, int bit){
        return (mask & (1 << bit)) != 0;
    }
    private static boolean checkBit(long mask, int bit){
        return (mask & (1L << bit)) != 0;
    }

    /////////////////////////////////////////////////////////////////////

    private static long getSum(int[] array) {
        long sum = 0;
        for (int value: array) {
            sum += value;
        }

        return sum;
    }

    private static Point getMinMax(int[] array) {
        int min = array[0];
        int max = array[0];

        for (int index = 0, size = array.length; index < size; ++index, ++index) {
            int value = array[index];

            if (index == size - 1) {
                min = min(min, value);
                max = max(max, value);
            } else {
                int otherValue = array[index + 1];

                if (value <= otherValue) {
                    min = min(min, value);
                    max = max(max, otherValue);
                } else {
                    min = min(min, otherValue);
                    max = max(max, value);
                }
            }
        }

        return new Point(min, max);
    }

    /////////////////////////////////////////////////////////////////////

    private static int[] getPrimes(int n) {
        boolean[] used = new boolean[n];
        used[0] = used[1] = true;

        int size = 0;
        for (int i = 2; i < n; ++i) {
            if (!used[i]) {
                ++size;
                for (int j = 2 * i; j < n; j += i) {
                    used[j] = true;
                }
            }
        }

        int[] primes = new int[size];
        for (int i = 0, cur = 0; i < n; ++i) {
            if (!used[i]) {
                primes[cur++] = i;
            }
        }

        return primes;
    }

    /////////////////////////////////////////////////////////////////////

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

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

    /////////////////////////////////////////////////////////////////////

    private static class MultiSet<ValueType> {

        public static <ValueType> MultiSet<ValueType> createMultiSet() {
            Map<ValueType, Integer> multiset = new HashMap<>();
            return new MultiSet<>(multiset);
        }

        private final Map<ValueType, Integer> multiset;
        private int size;

        public MultiSet(Map<ValueType, Integer> multiset) {
            this.multiset = multiset;
            this.size = 0;
        }

        public int size() {
            return size;
        }

        public void inc(ValueType value) {
            int count = get(value);
            multiset.put(value, count + 1);

            ++size;
        }

        public void dec(ValueType value) {
            int count = get(value);
            if (count == 0) return;

            if (count == 1) multiset.remove(value);
            else multiset.put(value, count - 1);

            --size;
        }

        public int get(ValueType value) {
            Integer count = multiset.get(value);
            return (count == null ? 0 : count);
        }
    }

    /////////////////////////////////////////////////////////////////////

    private static class IdMap<KeyType> extends HashMap<KeyType, Integer> {

        /**
         *
         */
        private static final long serialVersionUID = -3793737771950984481L;

        public IdMap() {
            super();
        }

        int getId(KeyType key) {
            Integer id = super.get(key);
            if (id == null) {
                super.put(key, id = size());
            }

            return id;
        }
    }

    /////////////////////////////////////////////////////////////////////

    private static int[] castInt(List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }

    private static long[] castLong(List<Long> list) {
        long[] array = new long[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Solver {

	public static void main(String[] Args) throws NumberFormatException,
			IOException {
		new Solver().Run();
	}

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

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

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

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

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

	int n,m;
	ArrayList<Integer> result;
	boolean[] alreadyExists;
	int[] history;
	int[] kolChange;
	int kolAlready=0;

	boolean check(int numLider){
		int maxNum=0;
		if (alreadyExists[numLider])
			maxNum=Integer.MAX_VALUE;
		int kolInRoom=kolAlready;
		if (kolInRoom>maxNum)
			return false;
		for (int i=0; i<m; i++){
			if (history[i]>0){
				kolInRoom++;
				if (history[i]==numLider)
					maxNum=Integer.MAX_VALUE;
			}
			if (history[i]<0){
				kolInRoom--;
				if (-history[i]==numLider)
					maxNum=0;
			}
			if (kolInRoom>maxNum)
				return false;
		}
		return true;
	}

	int findCandidate(){
		int result=0;
		int i=0;
		int kolInRoom=kolAlready;
		if (kolAlready==0) {
			kolInRoom++;
			//alreadyExists[history[i]]=true;
			result=history[i];
			i++;
		}
		for (;i<m; i++){
			if (history[i]>0)
				kolInRoom++;
			if (history[i]<0){
				kolInRoom--;
				if (kolInRoom==0){
					result=-history[i];
				}
			}
		}
		return result;
	}

	public void Run() throws NumberFormatException, IOException {
		//br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
		br=new BufferedReader(new InputStreamReader(System.in));  pw=new PrintWriter(new OutputStreamWriter(System.out));

		n=nextInt();
		m=nextInt();
		result=new ArrayList<Integer>();
		alreadyExists=new boolean[n+1];
		history=new int[m];
		kolChange=new int[n+1];
		for (int i=0; i<m; i++){
			char zn=nextToken().charAt(0);
			int num=nextInt();
			if (zn=='-'){
				if (kolChange[num]==0){
					alreadyExists[num]=true;
					kolAlready++;
				}
				kolChange[num]++;
				history[i]=-num;
			} else {
				history[i]=num;
				kolChange[num]++;
			}
		}
		for (int i=1; i<=n; i++){
			if (kolChange[i]==0)
				result.add(i);
		}

		int candidate=findCandidate();
		if (candidate>0)
			if (check(candidate))
				result.add(candidate);
		/*
		if (history[0]>0)
			if (check(history[0]))
				result.add(history[0]);

		if (history[m-1]<0 && history[0]!=-history[m-1])
			if (check(-history[m-1]))
				result.add(-history[m-1]);
		*/
		Collections.sort(result);
		pw.println(result.size());
		for (Integer elem : result) {
			pw.print(elem);
			pw.print(' ');
		}
		pw.println();
		pw.flush();
		pw.close();
	}

}


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

public class Main {

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

		//BufferedReader cin = new BufferedReader(new FileReader("test.txt"));
		 BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));

		String line;
		StringTokenizer st;

		line = cin.readLine();
		st = new StringTokenizer(line);

		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		//int b = Integer.parseInt(st.nextToken());

		boolean[] leader = new boolean[n];
		for(int i=0;i<n;i++) leader[i]=true;
		Set<Integer> list = new TreeSet<Integer>();
		char[] signs = new char[m];
		int[] ids = new int[m];

		char sign;
		int id;
		for(int i=0;i<m;i++){
			line = cin.readLine();
			st = new StringTokenizer(line);
			sign = st.nextToken().charAt(0);
			id = Integer.parseInt(st.nextToken());
			signs[i]=sign;
			ids[i]=id;
		}

		//int count=n;
		Iterator<Integer> ite;
		int tmpid;
		for(int i=0;i<m;i++){
			sign=signs[i];
			id=ids[i];

			if(sign=='+'){//not empty set
				if(list.size()!=0){
					leader[id-1]=false;
				}
				else if(i!=0&&(signs[i-1]!='-'||ids[i-1]!=id)){//empty set but someone else quit before
					leader[id-1]=false;
					//count--;
				}
				list.add(id);
			}
			else{//sign '-'
				if(i!=m-1&&(signs[i+1]!='+'||ids[i+1]!=id)){//not the last to quit
					leader[id-1]=false;
					//count--;
				}

				if(list.contains(id)==false){
					ite = list.iterator();
					while(ite.hasNext()){
						tmpid=ite.next();
						leader[tmpid-1]=false;
					}

				}
				//Mistake!!!!!!!removal needs to be last
				list.remove(id);
				if(list.size()!=0)
					leader[id-1]=false;
			}

		}
		int count=0;
		for(int i=0;i<n;i++){
			if(leader[i]==true)
				count++;
		}
		System.out.println(count);
		for(int i=0;i<n;i++){
			if(leader[i]==true)
				System.out.print((i+1)+" ");
		}

		cin.close();
	}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 *
 *
 * 3 2 3 5
 * -2 -1 4 -1 2 7 3
 *
 * 10 1 -10617 30886 -7223 -63085 47793 -61665 -14614 60492 16649 -58579 3 8 1
 * 10 4 7 1 7 3 7
 *
 * 22862 -34877
 *
 * @author pttrung
 */
public class B_CodeStrike2014_Final {

    public static long MOD = 1000000007;
    static int[] X = {0, 1};
    static int[] Y = {1, 0};
    static int[][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int m = in.nextInt();
        boolean[] check = new boolean[n];
        Arrays.fill(check, true);
        HashSet<Integer> cur = new HashSet();
        HashSet<Integer> pre = new HashSet();
        for (int i = 0; i < m; i++) {
            char op = in.next().charAt(0);
            int num = in.nextInt() - 1;

            if (op == '+') {
                if (cur.size() > 0 || (pre.size() > 0 && !pre.contains(num))) {
                    check[num] = false;
                }
                cur.add(num);
                if (pre.contains(num)) {
                    pre.remove(num);
                }
                for(int v : pre){
                    check[v] = false;
                }
            } else {
                if (cur.contains(num)) {
                    if (cur.size() > 1) {
                        check[num] = false;
                    }
                    cur.remove(num);
                    pre.add(num);
                } else {
                    if (cur.size() > 0) {
                        check[num] = false;
                    }
                    for (int v : cur) {
                        check[v] = false;
                    }
                    for (int v : pre) {
                        check[v] = false;
                    }
                    pre.add(num);
                }
            }
        }
        int c = 0;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (check[i]) {
                c++;
                builder.append(i + 1).append(" ");
            }
        }
        out.println(c);
        out.println(builder.toString());
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return x - o.x;
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

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

    public static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

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

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskB
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int p = in.nextInt();
            int pos = in.nextInt() - 1;

            int low = 0;
            int high = p + 1;
            while (high - low > 1)
            {
                int mid = low + (high - low) / 2;
                if (check(mid, p, pos, n))
                {
                    low = mid;
                } else
                {
                    high = mid;
                }
            }
            out.println(low);
        }

        private boolean check(int Q, int all, int pos, int n)
        {
            int[] a = new int[n];
            Arrays.fill(a, 1);

            all -= n;
            a[pos] = Q - 1;
            all -= Q - 1;
            for (int i = pos - 1, q = Q - 2; i >= 0 && q > 0; i--)
            {
                a[i] = q;
                all -= q;
                q--;
                if (all < 0)
                {
                    return false;
                }
            }
            for (int i = pos + 1, q = Q - 2; i < n && q > 0; i++)
            {
                a[i] = q;
                all -= q;
                q--;
                if (all < 0)
                {
                    return false;
                }
            }
            return all >= 0;
        }

    }

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

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

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

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

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

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}


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

public class CF
{

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

		Reader.init(System.in);

		int n=Reader.nextInt();
		int m=(Reader.nextInt()-n);
		int k=Reader.nextInt()-1;

		long ans=0;

		if(m>=1)
		{
			ans=1;m--;
		}

		int left=k,right=k;

		if(k-1>-1)
			left=k-1;

		if(k+1<n)
			right=k+1;

		while(m>0 && (left!=0 || right!=n-1)) {

			int xl=Math.abs(k-left);
			int xr=Math.abs(k-right);

			m-=(xl+xr);

			if(m>0)
			{
				m--;ans++;
			}

			if(left-1>-1)
				left--;

			if(right+1<n)
				right++;

		}

		if(m>0) {

			ans+=m/n;
		}
		System.out.println(ans+1);

	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

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

    static long nextLong() throws IOException{

    	return Long.parseLong( next() );
    }

}


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

public class line
{
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		int k = s.nextInt();
		int left = k-1;
		int right = n-k;
		int tleft = 0;
		int tright = 0;
		m = m- n;
		int ans = 1;
		if(n==1){
		    ans += m;
		    m=0;
		}
		while(m>0){
			ans++;
			if(tleft<left) {
				tleft++;
			}
			if(tright<right) {
				tright++;
			}
			m = m-tleft-tright-1;
		}
		System.out.println(ans);
	}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class b393a {

	static class Task{

		public void Solve(InputReader in, PrintWriter out)
		{
			int n=in.nextInt();
			int m=in.nextInt();
			int k=in.nextInt();
			m-=n;
			int len=0;
			int ans=1;
			while((len<=k-1|len<=n-k) & m>=(min(len,k-1)+min(len,n-k)+1))
			{
				m-=min(len,k-1)+min(len,n-k)+1;
				len++;
				ans++;
			}
			ans+=(m/n);
			out.println(ans);
	    }
     }

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

    static int[][] sort2D(int arr[][]){
        Arrays.sort(arr,new java.util.Comparator<int[]>(){
        public int compare(int[] a, int[] b) {
            return Integer.compare(a[0], b[0]);
        }});
        return arr;
    }

	static int[] di={1,0,-1,0,1,-1,-1,1};
	static int[] dj={0,1,0,-1,1,1,-1,-1};

	static class point{
		int x;int y;
		public point(int x,int y){
			this.x=x;
			this.y=y;
		}
	}

    static void sort(int arr[]){
		int cnt[]=new int[(1<<16)+1];
		int ys[]=new int[arr.length];
		for(int j=0;j<=16;j+=16){
			Arrays.fill(cnt,0);
			for(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}
			for(int i=1;i<cnt.length;i++){cnt[i]+=cnt[i-1];}
			for(int x:arr){ys[cnt[x>>j&0xFFFF]++]=x;}
			{ final int t[]=arr;arr=ys;ys=t;}
		}
		if(arr[0]<0||arr[arr.length-1]>=0)return;
		int i,j,c;
		for(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}
		for(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}
		for(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}
	}

    static int abs(int x){if(x>=0)return x;else return -x;}
    static long abs(long x){if(x>=0)return x;else return -x;}

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

    static int min(int x,int y){return x<y?x:y;}
    static int min(int x,int y,int z){return x<y?(x<z?x:z):(y<z?y:z);}
    static long min(long x,long y){return x<y?x:y;}
    static long min(long x,long y,long z){return x<y?(x<z?x:z):(y<z?y:z);}

    static int max(int x,int y){return x>y?x:y;}
    static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}
    static long max(long x,long y){return x>y?x:y;}
    static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}

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

    static void joutArray(int arr[][],int n,int m){
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++)
    		System.out.print(arr[i][j]+" ");
    		System.out.println();
    	}
    	System.out.println();
    }

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

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

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

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

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

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

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

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

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

        public char[] nextCharArray(){
        	char arr[]=next().toCharArray();
        	return arr;
        }

        public HashMap<Integer,Integer> inHashMap(int n){
        	HashMap<Integer,Integer> hm=new HashMap<>();
        	for(int i=0;i<n;i++){
    			int num=nextInt();
    			hm.put(num,hm.get(num)==null?1:hm.get(num)+1);
    		}
        	return hm;
        }

        public TreeMap<Integer,Integer> inTreeMap(int n){
        	TreeMap<Integer,Integer> tm=new TreeMap<>();
        	for(int i=0;i<n;i++){
    			int num=nextInt();
    			tm.put(num,tm.get(num)==null?1:tm.get(num)+1);
    		}
        	return tm;
        }
     }

   }import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class b393a {

	static class Task{

		public void Solve(InputReader in, PrintWriter out)
		{
			int n=in.nextInt();
			int m=in.nextInt();
			int k=in.nextInt();
			m-=n;
			int len=0;
			int ans=1;
			while((len<=k-1|len<=n-k) & m>=(min(len,k-1)+min(len,n-k)+1))
			{
				m-=min(len,k-1)+min(len,n-k)+1;
				len++;
				ans++;
			}
			ans+=(m/n);
			out.println(ans);
	    }
     }

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

    static int[][] sort2D(int arr[][]){
        Arrays.sort(arr,new java.util.Comparator<int[]>(){
        public int compare(int[] a, int[] b) {
            return Integer.compare(a[0], b[0]);
        }});
        return arr;
    }

	static int[] di={1,0,-1,0,1,-1,-1,1};
	static int[] dj={0,1,0,-1,1,1,-1,-1};

	static class point{
		int x;int y;
		public point(int x,int y){
			this.x=x;
			this.y=y;
		}
	}

    static void sort(int arr[]){
		int cnt[]=new int[(1<<16)+1];
		int ys[]=new int[arr.length];
		for(int j=0;j<=16;j+=16){
			Arrays.fill(cnt,0);
			for(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}
			for(int i=1;i<cnt.length;i++){cnt[i]+=cnt[i-1];}
			for(int x:arr){ys[cnt[x>>j&0xFFFF]++]=x;}
			{ final int t[]=arr;arr=ys;ys=t;}
		}
		if(arr[0]<0||arr[arr.length-1]>=0)return;
		int i,j,c;
		for(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}
		for(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}
		for(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}
	}

    static int abs(int x){if(x>=0)return x;else return -x;}
    static long abs(long x){if(x>=0)return x;else return -x;}

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

    static int min(int x,int y){return x<y?x:y;}
    static int min(int x,int y,int z){return x<y?(x<z?x:z):(y<z?y:z);}
    static long min(long x,long y){return x<y?x:y;}
    static long min(long x,long y,long z){return x<y?(x<z?x:z):(y<z?y:z);}

    static int max(int x,int y){return x>y?x:y;}
    static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}
    static long max(long x,long y){return x>y?x:y;}
    static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}

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

    static void joutArray(int arr[][],int n,int m){
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++)
    		System.out.print(arr[i][j]+" ");
    		System.out.println();
    	}
    	System.out.println();
    }

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

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

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

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

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

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

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

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

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

        public char[] nextCharArray(){
        	char arr[]=next().toCharArray();
        	return arr;
        }

        public HashMap<Integer,Integer> inHashMap(int n){
        	HashMap<Integer,Integer> hm=new HashMap<>();
        	for(int i=0;i<n;i++){
    			int num=nextInt();
    			hm.put(num,hm.get(num)==null?1:hm.get(num)+1);
    		}
        	return hm;
        }

        public TreeMap<Integer,Integer> inTreeMap(int n){
        	TreeMap<Integer,Integer> tm=new TreeMap<>();
        	for(int i=0;i<n;i++){
    			int num=nextInt();
    			tm.put(num,tm.get(num)==null?1:tm.get(num)+1);
    		}
        	return tm;
        }
     }

   }


import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    boolean has(int[] x, int[] y, int cx, int cy) {
        for (int i = 0; i < 8; i++) {
            if (x[i] == cx && y[i] == cy) return true;
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] x = new int[8];
        int[] y = new int[8];

        TreeSet<Integer> xset = new TreeSet<>();
        TreeSet<Integer> yset = new TreeSet<>();
        for (int i = 0; i < 8; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            xset.add(x[i]);
            yset.add(y[i]);
        }
        if (xset.size() != 3 || yset.size() != 3) {
            out.println("ugly");
            return;
        }
        int[] a = new int[3];
        int[] b = new int[3];
        int i = 0;
        for (int xx : xset) a[i++] = xx;
        i = 0;
        for (int yy : yset) b[i++] = yy;

        boolean ok = true;
        for (i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == 1 && j == 1) continue;
                if (!has(x, y, a[i], b[j])) ok = false;
            }
        }
        out.println(ok ? "respectable" : "ugly");
    }
}


import java.math.BigInteger;
import java.io.InputStream;

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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int[] x = new int[8];
        int[] y = new int[8];
        IOUtils.readIntArrays(in, x, y);
        boolean ok = true;
        for (int i = 0; i < 8; i++) {
            for (int j = i + 1; j < 8; j++) {
                if (x[i] == x[j] && y[i] == y[j]) ok = false;
            }
        }
        Arrays.sort(x);
        Arrays.sort(y);
        if (!(x[0] == x[1] && x[1] == x[2] && x[2] != x[3] && x[3] == x[4] && x[4] != x[5] && x[5] == x[6] && x[6] == x[7])) ok = false;
        if (!(y[0] == y[1] && y[1] == y[2] && y[2] != y[3] && y[3] == y[4] && y[4] != y[5] && y[5] == y[6] && y[6] == y[7])) ok = false;
        if (ok)
            out.printLine("respectable");
        else
            out.printLine("ugly");
    }
}

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 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 OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

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

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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

}

class IOUtils {

    public static void readIntArrays(InputReader in, int[]... arrays) {
        for (int i = 0; i < arrays[0].length; i++) {
            for (int j = 0; j < arrays.length; j++)
                arrays[j][i] = in.readInt();
        }
    }

    }


//Chores

import java.util.*;

public class Point implements Comparable<Point> {
	public Integer x;
	public Integer y;

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

	@Override
	public int compareTo(Point p) {
		if (this.x != p.x)
			return this.x.compareTo(p.x);
		return this.y.compareTo(p.y);
	}
}

public class HW {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int u, v;
		List<Point> a = new ArrayList<>();
		List<Integer> x = new ArrayList<>();
		List<Integer> y = new ArrayList<>();

		for (int i = 0; i < 8; i++) {
			u = sc.nextInt();
			v = sc.nextInt();
			Point p = new Point(u, v);

			a.add(p);

			if (!x.contains(u)) {
				x.add(u);
			}

			if (!y.contains(v)) {
				y.add(v);
			}
		}

		if (x.size() != 3 || y.size() != 3){
			System.out.print("ugly");
			return;
		}

		Collections.sort(x);
		Collections.sort(y);
		Collections.sort(a);

		int k = 0;
		boolean flag = true;
		for (int i=0;i<3;i++)
			for (int j=0;j<3;j++){
				if (i == 1 && j == 1)
					continue;
				if (a.get(k).x != x.get(i) || a.get(k).y != y.get(j))
					flag = false;
				k++;
			}

		if (flag)
			System.out.print("respectable");
		else
			System.out.print("ugly");

	}

}


import java.util.*;

public class Lecture3_Eight_Point_Sets {
    private static class Point implements Comparable<Point> {
        int x, y;
        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(Point o) {
            if (x == o.x && y == o.y)
                return 0;
            return (x < o.x || (x == o.x && y < o.y)) ? -1 : 1;
        }
    }
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        Point[] A = new Point[8];
        for(int i = 0; i < 8; i++)
            A[i] = new Point(inp.nextInt(), inp.nextInt());
        inp.close();
        Arrays.sort(A);
        boolean isUgly = false;
        for(int i = 1; i < 3; i++) {
            if (A[i].x != A[i - 1].x || A[i + 5].x != A[i + 4].x)
                isUgly = true;
            if (A[i].y == A[i - 1].y)
                isUgly = true;
            if (A[i].y != A[i + 5].y || A[i - 1].y != A[i + 4].y)
                isUgly = true;
        }
        if (A[4].x != A[3].x)
            isUgly = true;
        if (A[3].x == A[2].x || A[5].x == A[4].x)
            isUgly = true;
        if (A[1].y == A[0].y || A[2].y == A[1].y)
            isUgly = true;
        if (A[0].y != A[3].y) || A[2].y != A[4].y)
            isUgly = true;
        if (isUgly)
            System.out.print("ugly");
        else
            System.out.print("respectable");
    }
}


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

public class Main {
    static final int mod = 1000000007;
    static Boolean[] canReach;
    static int k, parent[];
    static int ans;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        k = sc.nextInt();
        generatePermutations(0, "");
        for (int i = k + 1; i <= n; i++)
            ans = (int) ((1l * ans * (n - k)) % mod);
        out.println(ans);
        out.flush();
        out.close();
    }

    static void generatePermutations(int i, String perm) {
        if (i == k) {
            char[] options = perm.toCharArray();
            parent = new int[k + 1];
            canReach = new Boolean[k + 1];
            for (int j = 1; j <= k; j++)
                parent[j] = options[j - 1] - '0';
            boolean add = true;
            for (int j = 1; j <= k; j++)
                add &= canReach(j);
            if (add) ans++;
            return;
        }
        for (int j = 1; j <= k; j++) {
            String tmp = perm + j;
            generatePermutations(i + 1, tmp);
        }

    }

    static boolean canReach(int i) {
        if (canReach[i] != null) return canReach[i];
        if (i == 1) return true;
        canReach[i] = false;
        return canReach[i] = canReach(parent[i]);
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

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

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

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

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

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}


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

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 Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
	  long M = 1000000007;
      long long res = 1;
      Scanner in = new Scanner(System.in);
	   int n = in.nextInt();
	   int k = in.nextInt();
       for (int i = 0; i < k - 1; i++)
         res = (res * k) % M;
       for (int i = 0; i < n - k; i++)
        res = (res * (n - k)) % M;
	    System.out.println(res);
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solver {

    public static void main(String[] Args) throws NumberFormatException,
            IOException {
        new Solver().Run();

    }

    PrintWriter pw;
    StringTokenizer Stok;
    BufferedReader br;

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

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

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

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

    public void Run() throws NumberFormatException, IOException {
        // br = new BufferedReader(new FileReader('input.txt'));
        // pw = new PrintWriter('output.txt');
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new OutputStreamWriter(System.out));

        int n = nextInt(), k = nextInt();
        long res = 1;
        for ( int i = 1; i < k; i++){
           res *= k;
           if (res > 1000000009)
              res %= 1000000009;
        }
        for ( int i = 1; i <= n-k; i++){
          res *= n-k;
          if (res > 1000000009)
              res %= 1000000009;
        }
        pw.print(res);
        pw.flush();
        pw.close();

    }

}


import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static syntax.Sugar.*;

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

@SuppressWarnings("unused")
public class B {

	private final static boolean autoflush = false;

	private final static int MOD = (int) 1e9 + 7;
	private final static double eps = 1e-9;
	private final static int INF = (int) 1e9;

	public B () {
		int N = sc.nextInt();
		int K = sc.nextInt();

		long res = modPow(N-K, N-K);
		if (K == 1)
			exit(res);

		int B = K-1; long Q = 0;
		int S = (int)modPow(B, B);
		out: for (int Z : rep(S)) {
			int [] C = digits(Z, B, K);
			for (int i : rep (1, K))
				if (C[i] >= i)
					++C[i];
			int [] G = new int [K]; G[0] = 1;
			for (int i : rep(1, K))
				if (dfs(i, C, G) == -1)
					continue out;
			++Q;
		}

		Q = mod(Q * K);
		res = mod(res * Q);
		exit(res);
	}

	int dfs(int i, int [] C, int [] G) {
		if (G[i] != 0)
			return G[i];
		G[i] = -1;
		return G[i] = dfs(C[i], C, G);
	}

	int [] digits(long N, int B, int sz) {
		int [] res = new int [sz];
		for (int i : sep(sz))
			if (N > 0) {
				res[i] = (int)(N % B);
				N /= B;
			}
		return res;
	}

	private static BigInteger BMOD = valueOf(MOD);

	private static long modPow(long b, long e) {
		return valueOf(b).modPow(valueOf(e), BMOD).longValue();
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	private static int [] sep(int N) { return sep(0, N); }
	private static int [] sep(int S, int T) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[T-1-i] = i; return res; }
	private static int [] seq(int S, int T) { return sep(S, T+1); }
	private static int [] ccw (int [] D) {
		return new int [] { -D[1], D[0] };
	}
	private static int [] cw (int [] D) {
		return new int [] { D[1], -D[0] };
	}
	private static int digitSum(long N) {
		int res = 0;
		for (; N > 0; res += N % 10, N /= 10);
		return res;
	}
	private static <T extends Comparable<T>> T max(T x, T y) {
		return x.compareTo(y) > 0 ? x : y;
	}
	private static long mod(long x) {
		return ((x % MOD) + MOD) % MOD;
	}
	private static long mod(long x, long mod) {
		return ((x % mod) + mod) % mod;
	}
	private static String reverse (String S) {
		return new StringBuilder(S).reverse().toString();
	}
	private static char [][] toCharArrays(String [] S) {
		int N = S.length;
		char [][] res = new char [N][];
		for (int i : rep(N))
			res[i] = S[i].toCharArray();
		return res;
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		private String next() {
			newLine();
			return line[index++];
		}
		private char nextChar() {
			return next().charAt(0);
		}
		private int nextInt() {
			return Integer.parseInt(next());
		}
		private long nextLong() {
			return Long.parseLong(next());
		}
		private double nextDouble() {
			return Double.parseDouble(next());
		}
		private String nextLine() {
			line = null;
			return readLine();
		}
		private String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}
		private char [] nextChars() {
			return next ().toCharArray ();
		}
		private Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i : rep(L.length))
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		private Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i : rep(L.length))
				res[i] = Long.parseLong(L[i]);
			return res;
		}
		private Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i : rep(L.length))
				res[i] = Double.parseDouble(L[i]);
			return res;
		}
		private String [] next (int N) {
			String [] res = new String [N];
			for (int i : rep(N))
				res[i] = next();
			return res;
		}
		private Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i : rep(N))
				res[i] = nextInt();
			return res;
		}
		private Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i : rep(N))
				res[i] = nextLong();
			return res;
		}
		private Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i : rep(N))
				res[i] = nextDouble();
			return res;
		}
		private String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i : rep(N))
				res[i] = nextStrings();
			return res;
		}
		private Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i : rep(N))
				res[i] = nextInts();
			return res;
		}
		private Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i : rep(N))
				res[i] = nextLongs();
			return res;
		}
		private Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i : rep(N))
				res[i] = nextDoubles();
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() {
			return index == line.length;
		}
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () {
			this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)));
		}
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) {
		printDelim(" ", o, a);
	}
	private static void cprint (Object o, Object... a) {
		printDelim("", o, a);
	}
	private static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}
	private static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	private static void NO() {
		throw new Error("NO!");
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i : rep(L))
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() {
		t = millis();
	}
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() {
		return System.currentTimeMillis();
	}
	private static void statics() {
		abs(0); valueOf(0); asList(new Object [0]); reverseOrder();
	}
	public static void main (String[] args) {
		new B();
		exit();
	}
}


import java.util.*;
import static java.lang.Math.*;
public class ProblemB {
    int M = 200;
    int P = 1000000007;
    int[][] choose = new int[M+1][M+1]; // stores (n choose k)

    void run() {
        // initalize pascals triangle
        choose[0][0] = 1;
        for (int n = 1; n <= M; ++n) {
            choose[n][0] = 1;
            choose[n][n] = 1;
            for (int k = 1; k < n; ++k) {
                choose[n][k] = (choose[n-1][k-1] + choose[n-1][k]) % P;
            }
        }

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] vals = new int[10];
        for (int i = 0; i < 10; ++i) {
            vals[i] = sc.nextInt();
        }
        int minDigits = 0;
        for (int a: vals) {
            minDigits += a;
        }
        long total = 0;
        for (int n = min(minDigits, 1); n <= N; ++n) { // actual length
            for (int i = 1; i < 10; ++i) { // leading digit
                int[] newvals = new int[10];
                for (int j = 0; j < 10; ++j) {
                    newvals[j] = vals[j];
                }
                if (newvals[i] > 0) {
                    --newvals[i];
                }
                d("solving", newvals, n);
                total += solve(newvals, n-1);
            }
        }
        p("%d\n", (total % P));
    }

    int solve(int[] vals, int n) {
        // dp[i][k] is how many ways with only first i characters, length k
        int[][] dp = new int[11][n+1];
        dp[0][0] = 1;
        for (int i = 1; i <= 10; ++i) {
            int d = i-1; // i-th digit (so i=1 gives d=0)
            for (int k = 0; k <= n; ++k) {
                int total = 0;
                // take r of character d
                for (int r = vals[d]; r <= k; ++r) {
                    long choices = choose[k][r];
                    long sub = dp[i-1][k-r];
                    long num = (choices * sub) % P;
                    total = (total + ((int) num)) % P;
                }
                dp[i][k] = total;
            }
        }
        int res = dp[10][n];
        d("returning", res);
        return res;
    }

    boolean debug = false;
    void p(String f, Object...params) {
        System.out.printf(f, params);
    }
    void d(Object...params) {
        if (debug) {
            p("DEBUG: %s\n", Arrays.deepToString(params));
        }
    }
    public ProblemB(String[] args) {
        if (args.length > 0 && args[0].equals("debug")) {
            debug = true;
        }
    }
    public static void main(String[] args) {
        new ProblemB(args).run();
    }
}


import static java.lang.Integer.max;

import java.math.BigInteger;

import java.util.Map;

import java.util.Scanner;

import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {

        Scanner in;

        in = new Scanner(System.in);

        int [] a =new int [20];

        int [][] C =new int [110][110];

        int [][] dp =new int [110][110];

        int n=in.nextInt();

        int mod=1000000007;

	for(int i=0;i<10;i++) a[i]=in.nextInt();

        int NN=110;

	for(int i=0;i<NN;i++){

            for(int j=0;j<NN;j++){

		if(j>i){

                    C[i][j]=0;

                    continue;

		}

		if(j==0){

                    C[i][j]=1;

                    continue;

		}

		if(i==j){

                    C[i][j]=1;

                    continue;

		}

		C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;

            }

	}

	for(int i=9;i>=0;i--){

            for(int len=0;len<=n;len++){

		if(i==9){

                    if(len<a[9]) dp[i][len]=0;

                    else dp[i][len]=1;

                    continue;

		}

		if(i!=0){

                    for(int j=a[i];j<=len;j++){

                        dp[i][len]=(int) (dp[i][len]+(long)C[len][j]*dp[i+1][len-j])%mod;

                    }

                }

		if(i==0){

                    for(int j=a[0];j<=len;j++){

                        dp[i][len]=(int) ((dp[i][len]+(long)C[len-1][j]*dp[i+1][len-j]%mod)%mod);

                    }

                }

            }

	}

	int ans=0;

	for(int i=1;i<=n;i++) ans=(ans+dp[0][i])%mod;

        System.out.println(ans);

    }

}


import java.util.*;
import static java.lang.Math.*;
public class ProblemB {
    int M = 200;
    int P = 1000000007;
    int[][] choose = new int[M+1][M+1]; // stores (n choose k)

    void run() {
        // initalize pascals triangle
        choose[0][0] = 1;
        for (int n = 1; n <= M; ++n) {
            choose[n][0] = 1;
            choose[n][n] = 1;
            for (int k = 1; k < n; ++k) {
                choose[n][k] = (choose[n-1][k-1] + choose[n-1][k]) % P;
            }
        }

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] vals = new int[10];
        for (int i = 0; i < 10; ++i) {
            vals[i] = sc.nextInt();
        }
        int minDigits = 0;
        for (int a: vals) {
            minDigits += a;
        }
        long total = 0;
        for (int n = minDigits; n <= N; ++n) { // actual length
            for (int i = 1; i < 10; ++i) { // leading digit
                int[] newvals = new int[10];
                for (int j = 0; j < 10; ++j) {
                    newvals[j] = vals[j];
                }
                if (newvals[i] > 0) {
                    --newvals[i];
                }
                d("solving", newvals, n);
                total += solve(newvals, n-1);
            }
        }
        p("%d\n", (total % P));
    }

    int solve(int[] vals, int n) {
        // dp[i][k] is how many ways with only first i characters, length k
        int[][] dp = new int[11][n+1];
        dp[0][0] = 1;
        for (int i = 1; i <= 10; ++i) {
            int d = i-1; // i-th digit (so i=1 gives d=0)
            for (int k = 0; k <= n; ++k) {
                int total = 0;
                // take r of character d
                for (int r = vals[d]; r <= k; ++r) {
                    long choices = choose[k][r];
                    long sub = dp[i-1][k-r];
                    long num = (choices * sub) % P;
                    total = (total + ((int) num)) % P;
                }
                dp[i][k] = total;
            }
        }
        int res = dp[10][n];
        d("returning", res);
        return res;
    }

    boolean debug = false;
    void p(String f, Object...params) {
        System.out.printf(f, params);
    }
    void d(Object...params) {
        if (debug) {
            p("DEBUG: %s\n", Arrays.deepToString(params));
        }
    }
    public ProblemB(String[] args) {
        if (args.length > 0 && args[0].equals("debug")) {
            debug = true;
        }
    }
    public static void main(String[] args) {
        new ProblemB(args).run();
    }
}


import java.io.PrintStream;
import java.util.Scanner;

/**
 * @author Roman Elizarov
 */
public class Round_131_B {
	private static final int MOD = 1000000007;

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

	int n;
	int[] a;

	void go() {
		// read input
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		a = new int[10];
		for (int i = 0; i < 10; i++)
			a[i] = in.nextInt();

		// solve
		int result = solve();

		// write result
		PrintStream out = System.out;
		out.println(result);
	}

	int[][] c;

	int solve() {
		c = new int[101][101];
		c[0][0] = 1;
		for (int i = 1; i <= 100; i++) {
			c[i][0] = 1;
			for (int j = 1; j <= 100; j++)
				c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
		}

		int sum = 0;
		for (int i = 0; i < 10; i++)
			sum += a[i];
		int res = 0;
		for (int len = Math.max(1, sum); len <= n; len++) {
			for (int fst = 1; fst < 10; fst++) {
				int slots = len - 1;
				int minSum = sum;
				if (a[fst] > 0)
					minSum--;
				int combos = compute(0, fst, minSum, slots);
				res = (res + combos) % MOD;
			}
		}
		return res;
	}

	private int compute(int i, int fst, int minSum, int slots) {
		if (minSum > slots)
			return 0;
		if (i == 10)
			return slots == 0 ? 1 : 0;
		int min = a[i];
		if (min > 0 && i == fst)
			min--;
		int res = 0;
		for (int k = min; k <= slots; k++)
			res = (res + mul(compute(i + 1, fst, minSum - min, slots - k), c[slots][k])) % MOD;
		return res;
	}

	private int mul(long a, long b) {
		return (int)((a * b) % MOD);
	}
}


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

public class C {

    MyScanner in;
    PrintWriter out;

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

    public void run() throws Exception {
        in = new MyScanner();
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    public void solve() throws Exception {
        char[] a = in.next().toCharArray();
        int[] chars = new int[26];
        for (int i = 0; i < 6; i++) {
            chars[a[i] - 'A']++;
        }
        int[] nums = new int[6];
        int k = 0;
        for (int i = 0; i < 26; i++) {
            if (chars[i] != 0) {
                nums[k++] = chars[i];
            }
        }
        Arrays.sort(nums);
        String code = Arrays.toString(nums);
        if (code.equals("[0, 0, 0, 0, 0, 6]")) {
            out.println("1");
        } else if (code.equals("[0, 0, 0, 0, 3, 3]")) {
            out.println("2");
        } else if (code.equals("[0, 0, 0, 0, 2, 4]")) {
            out.println("2");
        } else if (code.equals("[0, 0, 0, 2, 2, 2]")) {
            out.println("5");
        } else if (code.equals("[0, 0, 0, 0, 1, 5]")) {
            out.println("1");
        } else if (code.equals("[0, 0, 0, 1, 2, 3]")) {
            out.println("3");
        } else if (code.equals("[0, 0, 0, 1, 1, 4]")) {
            out.println("2");
        } else if (code.equals("[0, 0, 1, 1, 2, 2]")) {
            out.println("8");
        } else if (code.equals("[0, 0, 1, 1, 1, 3]")) {
            out.println("5");
        } else if (code.equals("[0, 1, 1, 1, 1, 2]")) {
            out.println("15");
        } else if (code.equals("[1, 1, 1, 1, 1, 1]")) {
            out.println("30");
        }
    }

    class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() throws Exception {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

        boolean nextBoolean() throws Exception {
            return Boolean.parseBoolean(next());
        }

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

}


import java.util.*;

public class Problem {

	static boolean nextPermutation(char[] a)
    {
        int n = a.length;
        int i = n-2;
        while(i >= 0 && a[i] >= a[i+1]) {
            i--;
        }
        if(i < 0) {
            return false;
        }
        for(int j = n-1; j >= i; j--){
            if(a[j] > a[i]){
                char temp = a[i];
                a[i] = a[j];
                a[j] = temp;
                break;
            }
        }
        for(int j = i+1; j < (n+i+1)/2; j++){
            char temp = a[j];
            a[j] = a[n+i-j];
            a[n+i-j] = temp;
        }
        return true;
    }

	static char ref;
	static int[][] neigh = new int[][] {{1,2,4,3},{0,2,5,3},{0,1,5,4},{0,1,5,4},{0,2,5,3},{1,2,4,3}};

	static boolean equals(String a, String b){
		for(int i = 0; i < 6; i++){
			if(a.charAt(i) == ref){
				for(int j = 0; j < 6; j++){
					if(b.charAt(j) == ref){
						for(int start = 0; start < 4; start++){
							boolean ok = true;
							for(int k = 0; k < 4; k++){
								if(a.charAt(neigh[i][k]) != b.charAt(neigh[j][(start+k)%4])){
									ok = false;
								}
							}
							if(ok){
								return true;
							}
						}
					}
				}
			}
		}
		return false;
	}

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		char[] input = in.next().toCharArray();
		Arrays.sort(input);
		ref = input[0];
		LinkedList<String> counter = new LinkedList<String>();
        do {
        	String cur = new String(input);
        	boolean ok = true;
        	for(String str : counter){
        		if(equals(str, cur)){
        			ok = false;
        			break;
        		}
        	}
        	if(ok) counter.addLast(cur);
        }while(nextPermutation(input));
        System.out.println(counter.size());
	}
}


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

public class Main {

    char[] tmp;
    boolean[] vist;
    char[] str;
    Set<Node> S;
    private void dfs(int t) {
        if (t == 6) {
            Node l = new Node();
            for (int i = 0; i < 6; ++i) {
                l.str[i] = this.str[i];
            }
            S.add(l);
        }
        for (int i = 0; i < 6; ++i) {
            if (vist[i]) continue;
            str[t] = tmp[i];
            vist[i] = true;
            dfs(t + 1);
            vist[i] = false;
        }
    }

    public void run() {
        S = new TreeSet<Node>();
        tmp = cin.next().toCharArray();
        vist = new boolean[6];
        str = new char[6];
        dfs(0);
        int ans = S.size();
        if (ans != 1) --ans;
        System.out.println(ans);
    }

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

    Scanner cin = new Scanner(System.in);
}

class Node implements Comparable<Node>{
    char[] str = new char[6];
    static int[][] dir = {
        {1, 2, 3, 4, 5},
        {5, 2, 0, 4, 3},
        {1, 5, 3, 0, 4},
        {0, 2, 5, 4, 1},
        {1, 0, 3, 5, 2},
        {1, 4, 3, 2, 0}
    };
    public int compareTo(Node o) {

        for (int i = 0; i < 6; ++i) {
            for (int j = 0; j < 1; ++j) {
                if (o.str[i] == str[j]) {
                    if (o.str[dir[i][4]] == str[dir[j][4]]) {
                        char[] t1 = new char[4];
                        char[] t2 = new char[4];
                        for (int k = 0; k < 4; ++k) {
                            t1[k] = o.str[dir[i][k]];
                            t2[k] = str[dir[j][k]];
                        }
                        Arrays.sort(t1);
                        Arrays.sort(t2);
                        for (int k = 0; k < 4; ++k) {
                            if (t1[k] != t2[k]) {
                                break;
                            }
                            if (k == 3) {
                                return 0;
                            }

                        }
                    }
                }
            }
        }
        for (int i = 0; i < 6; ++i) {
            if (str[i] != o.str[i]) {
                return str[i] - o.str[i];
            }
        }
        return -1;
    }
    public String toString() {
        StringBuilder st = new StringBuilder();
        for (int i = 0; i < 6; ++i) {
            st.append(str[i]);
        }
        return st.toString();
    }
}


import java.util.Scanner;

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

	int a[] = {0,0,0,0,0,0};
	String s = input.next();
	for (int i = 0; i < 6; i++)
	    if (s.charAt(i) == 'R')
		a[0]++;
	    else if (s.charAt(i) == 'O')
		a[1]++;
	    else if (s.charAt(i) == 'Y')
		a[2]++;
	    else if (s.charAt(i) == 'G')
		a[3]++;
	    else if (s.charAt(i) == 'B')
		a[4]++;
	    else if (s.charAt(i) == 'V')
		a[5]++;

	int ans =0;
	int num = 0;
	for (int i = 0; i < 6; i++)
	    if (a[i] > 0)
		num++;
	if (num == 1)
	    ans = 1;
	if (num == 2) { // (5,1) (4,2) (3,3)
	    for (int i = 0; i < 6; i++)
		if (a[i] == 5)
		    ans = 1;
		else if (a[i] == 4)
		    ans = 2;
		else if (a[i] == 3)
		    ans = 3;
	}
	if (num == 3) { // (4,1,1) (3,2,1)
	    boolean mode = false;
	    for (int i = 0; i < 6; i++)
		if (a[i] == 4)
		    mode = true;
	    if (mode)
		ans = 2;
	    else
		ans = 8;
	}
	if (num == 4) { // (3,1,1,1) (2,2,1,1)
	    boolean mode = false;
	    for (int i = 0; i < 6; i++)
		if (a[i] == 3)
		    mode = true;
	    if (mode)
		ans = 15;
	    else
		ans = 8;
	}
	if (num == 5) {
	    ans = 6 + 12;
	}
	if (num == 6)
	    ans = 30;
	System.out.println(ans);

    }
}