→ Исходный код
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hippskill (Hippskill@gmail.com)
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        boolean[] generate_polyn(int n) {
            boolean[] polyn = new boolean[n + 1];
            for (int i = 1; i < n; i++) {
                String new_num = Integer.toString(i);
                String new_num1 = new StringBuffer(new_num).reverse().toString();
                if (new_num.equals(new_num1))
                    polyn[i] = true;
            }
            return polyn;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            boolean[] primes = IntegerUtils.generatePrimalityTable(1000000);
            boolean[] polyn = generate_polyn(1000000);
            polyn[0] = false;
            int was_primes = 0;
            int was_polyn = 0;
            int p = in.readInt();
            int q = in.readInt();
            boolean ok = false;
            int ans = 0;
            for (int i = 0; i < 1000000; i++) {
                if (primes[i])
                    was_primes++;
                if (polyn[i])
                    was_polyn++;

                if (was_primes > (double) p / q * was_polyn) {
                    ok = true;
                    ans = i - 1;

                }
            }
            if (ok)
                out.printLine(ans);
            else
                out.printLine("Palindromic tree is better than splay tree");
        }

    }

    static class IntegerUtils {
        public static boolean[] generatePrimalityTable(int upTo) {
            boolean[] isPrime = new boolean[upTo];
            if (upTo < 2)
                return isPrime;
            Arrays.fill(isPrime, true);
            isPrime[0] = isPrime[1] = false;
            for (int i = 2; i * i < upTo; i++) {
                if (isPrime[i]) {
                    for (int j = i * i; j < upTo; j += i)
                        isPrime[j] = false;
                }
            }
            return isPrime;
        }

    }

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

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

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

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

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

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

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

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void printLine(int i) {
            writer.println(i);
        }

    }
}


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

public class CF {

	static InputReader in = new InputReader(System.in);
	static long rightLimit = ((long)1 << 32l) / (long) 100;

	public static void main(String[] args) {

		int p = in.nextInt();
		int q = in.nextInt();

		int primes = 0;
		int palind = 0;

		int max = -1;

		for (int i = 1; i < rightLimit; i++) {
			if (prime(i))
				primes += q;
			if (palind(i))
				palind += p;

			if (primes <= palind)
				max = i;
		}

		System.out.println(max);

	}

	static boolean prime(int p) {
		if (p == 2)
			return true;
		if (p == 1 || p % 2 == 0)
			return false;
		for (int i = 3; i * i <= p; i += 2)
			if (p % i == 0)
				return false;
		return true;
	}

	static boolean palind(int p) {
		String s = p + "";

		for (int i = 0; i < s.length() / 2; i++)
			if (s.charAt(i) != s.charAt(s.length() - 1 - i))
				return false;
		return true;
	}

}

class InputReader {
	private BufferedReader reader;
	private 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 readLine() {
		try {
			return reader.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

}


import java.io.*;
import java.util.*;
public class b{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int sevens = 0, fours = 0;
		for(int i = 0; i < n; i++){
			if(s.charAt(i) == '4'){
				fours++;
			{
			else if(s.charAt(i) == '7'){
				sevens++;
			}
		}
		int ans = 0;
		if(fours > sevens){
			ans = 4;
		}
		else if(sevens < fours){
			ans = 7;
		}
		else if(sevens == 0 && fours == 0){
			ans = -1;
		}
		else{
			ans = 4;
		}
		System.out.println(ans);
	}
}


import java.util.*;
public class lucky {
    public static void main(String[]args){
        Scanner sc= new Scanner(System.in);
       4 String s=sc.next();
        int c=0,
        int d=0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='4')
                c++;
            if(s.charAt(i)=='7')
                d++;
        }
        if(c==0 && d==0)
            System.out.println(-1);
        else{
            if(c>=d)
                System.out.println(4);
            else System.out.println(7);
        }
    }

}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

import java.util.BitSet;
public class A {
		    public static void main(String[] args) {
		        FastReader sc=new FastReader();
		        String s=sc.next();
		        int c1=0,c2=0;
		        for(int i=0;i<s.length();i++){
		        	if(s.charAt(i)=='4') c1++;
		        	else if(s.charAt(i)=='7') c2++;

		        }
		        if(c1==0 && c2==0) { System.out.println(-1); return; }
		        if(c1>=c2) System.out.println(4);
		        else if(c2>c1) System.out.println(7);

		    }

		    static class FastReader
		    {
		        BufferedReader br;
		        StringTokenizer st;

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

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

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

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

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

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


import java.util.Scanner;

public class LackPodstroka
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String data = in.next();
        char dat [] = new char[data.length()];
        dat = data.toCharArray();
        String a[] = new String[dat.length];
        for (int i = 0; i < a.length; i++)
        {
            a[i] = Character.toString(dat[i]);
        }
        int data_[] = new int[data.length()];
        int dano [] = new int[]{4,7};
        for (int i = 0; i < data_.length; i++)
        {
            data_[i] = Integer.parseInt(a[i]);
        }
        int FOUR = 0;
        int SEVEN = 0;
        int FOUR_SEVEN = 0;
        int SEVEN_FOUR = 0;
        for (int i = 0; i < data_.length; i++)
        {
            if(data_[i]==dano[0])
            {
                FOUR++;
            }
            if(data_[i]==dano[1])
            {
                SEVEN++;
            }
            if(i != data_.length-1)
            {
                if(data_[i]==dano[0]&&data_[i+1]==dano[1])
                {
                    FOUR_SEVEN++;
                }
                if(data_[i]==dano[1]&&data_[i+1]==dano[0])
                {
                    SEVEN_FOUR++;
                }
            }
        }
        if(FOUR==0&&SEVEN==0&&FOUR_SEVEN==0&&SEVEN_FOUR==0)
        {
            System.out.print("-1");
        }

        if(FOUR>0&&SEVEN>0&&FOUR_SEVEN>0&&SEVEN_FOUR>0)
        {
            if(FOUR==SEVEN && SEVEN==FOUR_SEVEN)
            {
                System.out.print("4");
            }

            if(FOUR>SEVEN&&FOUR>FOUR_SEVEN&&FOUR>SEVEN_FOUR)
            {
                System.out.print("4");
            }
            if(SEVEN>FOUR&&SEVEN>FOUR_SEVEN&&SEVEN>SEVEN_FOUR)
            {
                System.out.print("7");
            }
            if(SEVEN_FOUR>SEVEN&&SEVEN_FOUR>FOUR_SEVEN&&SEVEN_FOUR>FOUR)
            {
                System.out.print("74");
            }
            if(FOUR_SEVEN>SEVEN&&FOUR_SEVEN>FOUR&&FOUR_SEVEN>SEVEN_FOUR)
            {
                System.out.print("47");
            }
        }
    }

}


va.util.Scanner;

public class C {

    /**
     * @param args
     */
    static int a , b ,n;
    static long[][] dp;
    static int mod = 1000000007;
    public static void main(String[] args)
    {
//      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner scan = new Scanner(System.in);
        a = scan.nextInt();
        b = scan.nextInt();
        n = scan.nextInt();
        long res = 0;
        long[] f = new long[n+1];
        f[0] = f[1] = 1;
        for(int i = 2 ; i <= n;i++)
            f[i] = (f[i-1]*i)%mod;
        for(int x = 0; x <= n;x++)
        {
            int y = n-x;
            long sum = (long)(a*x)+(long)(y*b);
            int c = 1,t;
            while(sum > 0 && c == 1)
            {
                t = (int) (sum%10);
                if(t != a && t != b)
                    c= 0;
                sum/=10;
            }
            if(c == 1)
                res = (res+f[n]/(f[x]*f[y]))%mod;
        }
        System.out.println(res);
    }
}


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

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

    static class BeautifulNumbers {
        static long fact;
        static long MOD = (long) (Math.pow(10, 9) + 7);

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            int n = in.nextInt();
            fact = new long[n + 1];
            long ans = 0;

            fact[0] = 1;
            for (int i = 1; i <= n; i++) {
                fact[i] = i * fact[i - 1];
            }

            for (int i = 0; i <= n; i++) {
                long val = (i * a) + ((n - i) * b);

                if (check(val, a, b)) {
                    ans += getComb(i, n);
                    ans %= MOD;
                }

            }

            out.println(ans);
        }

        private long getComb(int i, int n) {
            long mul = fact[n];
            long div = fact[n - i] * fact[i];
            mul %= MOD;
            div %= MOD;

            div = pow(div, MOD - 2);

            return (mul * div) % MOD;

        }

        private long pow(long base, long p) {
            if (p == 0) {
                return 1;
            }

            long po = pow(base, p / 2) % MOD;
            po = (po * po) % MOD;

            if (p % 2 == 0) {
                return po % MOD;
            } else {
                return (po * base) % MOD;
            }
        }

        private boolean check(long val, long a, long b) {

            while (val > 0) {
                if (val % 10 == a || val % 10 == b) {
                    val = val / 10;
                } else {
                    return false;
                }
            }

            return true;
        }

    }

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

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

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

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

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

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

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

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

        }

    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
    public static long mod = 1000000007;

    public static void main(String[] args)throws IOException{
        BufferedReader br =  new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        char[] c = st.nextToken().toCharArray();
        int n = c.length;
        st = new StringTokenizer(br.readLine());
        int k = Integer.parseInt(st.nextToken());
        long[] t = new long[n+1];
        int nb = 0;
        for(int i=0;i<n;i++){
            if(c[i]=='1'){
                int l = n-i-1;
                for(int j=0;j<=l;j++){
                    t[nb+j] += C(j,l);
                    t[nb+j] %= mod;
                }
                nb++;
            }
        }
        t[nb]++;
        t[nb]%=mod;
        int[] res = new int[n+1];
        res[1] = 0;
        for(int i=2;i<=n;i++){
            nb = Integer.bitCount(i);
            res[i] = res[nb]+1;
        }
        long result = 0;
        for(int i=1;i<=n;i++){
            if(res[i]==k){
                result += t[i];
                result %= mod;
            }
        }
        out.println(result);
        out.flush();
   }
}


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

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

	static class TaskC {
		private static long[][] dp;
		private static byte a;
		private static byte b;
		private static char ab;
		private static char ba;

		private static long ncr (int n, int r) {
			if (r == 1) return n;
			if (n == r || r == 0) return 1;
			if (dp[n][r] != -1) {
				return dp[n][r];
			}
			dp[n][r] = ncr (n-1, r)+ncr (n-1, r-1);
			if (dp[n][r]>InputReader.inf) {
				dp[n][r] %= InputReader.inf;
			}
			return dp[n][r];
		/*//use this method only when calculating ncr less times
		if(r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
    	long ans = 1;
		for(int i = 1; i <= r; i++) {
			ans *= n - r + i;
			ans /= i;
		}
		return ans;*/
		}

		private static boolean check (long os) {
			String str = Long.toString (os);
			int len = str.length ();
			for (int i = 0; i<len; i++) {
				if (str.charAt (i) != ab && str.charAt (i) != ba) {
					return false;
				}
			}
			return true;
		}

		public void solve (int testNumber, InputReader in, PrintWriter out) {
/* I have found 2 ways, main eqn is a*x+b*(n-x)=such a number that has only a and b. Now whether brute over x or
 * brute over r.h.s. I think brute over x is better choice, after finding x, ans+=n!/x!(n-x)! that means ncx*/
			a = (byte) in.nextInt ();
			b = (byte) in.nextInt ();
			ab = (char) (a+'0');
			ba = (char) (b+'0');
			int n = in.nextInt ();
			dp = new long[n+5][n/2+5];
			for (int i = 0; i<n+5; i++) {
				Arrays.fill (dp[i], -1);
			}
			long ans = 0;//when modding try to use if(ans>1e14) ans%=inf
			long os = -a+b*(n+1);
			for (int i = 0; i<=n; i++) {
				os += a;
				os -= b;
				if (check (os)) {
					if (i>n/2) {
						ans += ncr (n, n-i);
					}
					else ans += ncr (n, i);
					if (ans>1e14) {
						ans %= InputReader.inf;
					}
				}
			}
			out.println (ans);
		}

	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;
		public static final int inf = 1000000007;

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

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

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

	}
}


mport java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      Scanner scanner= new Scanner(System.in);
      int n=scanner.nextInt();
      int m=scanner.nextInt();
      int z=scanner.nextInt();
      int counter=0;
      for (int i=1; i<=z; i++ ){
          if (n==m){
              counter=z;
              break;
          }else{
              if ((i%n==0 || i==n) && (i%m==0 || i==m)){
                counter++;
              }
          }

      }
        System.out.println(counter);
    }
}


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

public class Main {

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

		BufferedReader f=new BufferedReader(new FileReader(System.in));
		PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(System.out)));
		StringTokenizer st=new StringTokenizer(f.readLine());

		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		int z=Integer.parseInt(st.nextToken());
		int kills=0;

		for(int i = 1; i * m <= z; i++) {
			int c = i * m;
			if (c % n == 0)
				kills++;
		}
		out.println(kills);

		}
}


import java.io.*;
import java.util.*;
public class HelloWorld{

     public static void main(String []args){
         Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         int m=sc.nextInt();
         int z=sc.nextInt();
         int g=gcd(n,m);
         int lcm=(n*m)/g;
         System.out.println(z/lcm);
     }
     public static int gcd(int a,int b)
     {
         if(b==0)
         return a;
         return(b,a%b);
     }
}


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

public class Main {

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

		BufferedReader f=new BufferedReader(new FileReader(System.in));
		PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(System.out)));
		StringTokenizer st=new StringTokenizer(f.readLine());

		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		int z=Integer.parseInt(st.nextToken());
		int kills=0;

		for(int i = 1; i * m <= z; i++) {
			int c = i * m;
			if (c % n == 0)
				kills++;
		}
		out.println(kills);

		}
}


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

public class Main{

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

		BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
		System.out)));
		StringTokenizer st=new StringTokenizer(f.readLine());

		int a=Integer.parseInt(st.nextToken());
		int x= 0;
                int y = 0;
                int min = 100000000000000000000;
		for ( int i = 1; i < Math.sqrt(a)+1; i++ ){
                    if (a%i == 0 && a>=i){
                        int b = a/i;
                        if (min > Math.abs(b-i)){
                            x = b;
                            y = i;
                            min = b-i;

                        }

                    }

                }
                    System.out.println(y);
                    System.out.println(x);
		System.out.close();
		}

}


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

/**
 * Generated by Contest helper plug-in
 * Actual solution is at the bottom
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	private boolean finished = false;

	public abstract int read();

	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 String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(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 void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskA implements Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int num = in.readInt();
		double sqrt = Math.sqrt(num);
		int intSqrt = (int)(sqrt);
		if (sqrt == intSqrt) {
			out.print(intSqrt);
			out.print(" ");
			out.print(intSqrt);
		} else {
			for (int i = intSqrt; i >= 0; i--) {
				if (num % i == 0) {
					out.print(num/i);
					out.print(" ");
					out.print(i);
					break;
				}
			}
		}
	}
}


import java.util.Scanner;
public class SolutionA {
    public static void main(String[] args){
        int pixelNumber = new Scanner(System.in).nextInt();
        int a=1;
        float temp;
        temp = pixelNumber;
            for (int i=2;i<100000;i++){
                if (temp>=a) {
                temp/=i;
                if (temp == Math.round(temp)){
                     a*=i;
                     i--;

                     continue;
                } else {
                temp*=i;
                continue;
                }
                } else break;
            }
        System.out.println((Integer)temp + " " + a);
        }
        }


import java.util.Scanner;
public class SolutionA {
    public static void main(String[] args){
        int pixelNumber = new Scanner(System.in).nextInt();
        int a=1,b;
        float temp;
        temp = pixelNumber;
            for (int i=2;i<100000;i++){
                if (temp>=a) {
                temp/=i;
                if (temp == Math.round(temp)){
                     a*=i;
                     i--;

                     continue;
                } else {
                temp*=i;
                continue;
                }
                } else break;
            }
        b = (Integer) temp;
        System.out.println(b + " " + a);
        }
        }


import java.io.BufferedReader;
import java.io.BufferedWrite;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static final InputStreamReader standardInput = new InputStreamReader(System.in);
    private static final BufferedReader bufferedReader = new BufferedReader(standardInput);
    private static final Scanner scanner = new Scanner(bufferedReader);

    private static final OutputStreamWriter standardOutput = new OutputStreamWriter(System.out);
    private static final BufferedWriter bufferedWriter = new BufferedWriter(standardOutput);
    private static final PrintWriter printWriter = new PrintWriter(bufferedWriter);

    public static void main(String[] args) {
        long l = scanner.nextLong();
        long r = scanner.nextLong();
        if (l % 2 == 0 && r - l >= 2) {
            printWriter.println(l + " " + (l + 1) + " " + (l + 2));
        } else if (r - l < 3) {
            printWriter.println(-1);
        } else {
            printWriter.println((l + 1) + " " + (l + 2) + " " + (l + 3));
        }
        printWriter.flush();
        scanner.close();
    }
}


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

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

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

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

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

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

	static /*int*/long gcd(/*int*/long x, /*int*/long y){
  	      if(x==0)
    	        return y;
      	      if(y==0)
        	        return x;
     	      /*int*/long r=0, a, b;
      	      a = (x > y) ? x : y; // a is greater number
      	      b = (x < y) ? x : y; // b is smaller number
      	      r = b;
     	     while(a % b != 0){
     	        r = a % b;
     	        a = b;
      	        b = r;
     	   }
                   return r;
              }

	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		long l = nextLong();
		long r = nextLong();
		if(r-l<3){
		    writer.println("-1");
		    return;
		}
		if(l%2!=1){
		    l++;
		}
		writer.println(l+" "+(l+1)+" "(l+2));
	}
}


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

public class counterexample {
	public static BigInteger HCF(BigInteger a, BigInteger b) {
		if (b.compareTo(BigInteger.ZERO) == 0)
			return a;
		return HCF(b, a.mod(b));
	}

	public static void main(String args[]) {
		int flag = 0;
		Scanner sc = new Scanner(System.in);
		BigInteger l = sc.nextBigInteger();
		BigInteger r = sc.nextBigInteger();
		BigInteger a = l;
		BigInteger b = l.add(BigInteger.ONE);
		BigInteger c = l.add(BigInteger.TWO);
		while (c.compareTo(r) < 1 || c.compareTo(r) == 0) {

			if (HCF(b, c).compareTo(BigInteger.ONE) == 0 && HCF(a, c).compareTo(BigInteger.ONE) != 0) {
				flag = 1;
				break;
			}
			c = c.add(BigInteger.ONE);
			// System.out.print(c+" ");
		}
		if (flag == 1)
			System.out.println(a + " " + b + " " + c);
		else
			System.out.println(-1);
	}
}


import java.util.*;
public class coPrime {

	public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	long a=scn.nextLong();
	long b= scn.nextLong();
	if(a-b==-1 ||a-b==1) {
		System.out.println("-1");
	}
	else if(a%2==0 && b%2==0) {
		System.out.println(a+" "+(a+1)+" "+b);
	}
	else if(a%2==0 && b%2!=0)
	{
		System.out.println(a+" "+(a+1)+" "+(a+2));
	}
	else if(a%2!=0 && b%2==0) {
		System.out.println((a+1)+" "+(a+2)+" "+(a+3));
	}
	else
		System.out.println(a+" "+(a+1)+" "+b);


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

// public class Solution
class Solution
{
	static BufferedReader br;
	static String nextIntBuffer[];
	static int nextIntBase;
	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	static String next() throws IOException {
		if(nextIntBase>=nextIntBuffer.length) {
			nextIntBase =0;
			nextIntBuffer = br.readLine().split(" ");
		}
		return nextIntBuffer[nextIntBase++];
	}

	public static void main(String[] args) throws IOException {
		br=new BufferedReader(new InputStreamReader(System.in));
		nextIntBuffer = new String[0];

		String[] time=next().split(":");
		int hr=Integer.parseInt(time[0]);
		int min=Integer.parseInt(time[1]);
		int current=hr*60+min;

		String mins="";
		if(hr/10==0)
			mins=hr+"0";
		else
			mins=(new StringBuilder(time[0])).reverse().toString();
		int new_min=Integer.parseInt(mins)+hr*60;
		if(new_min<current)
		{
			if(hr+1>23)
			{
				new_min=24*60;
			}
			else
			{
				if((hr+1)/10==0)
					mins=(hr+1)+"0";
				else
					mins=(new StringBuilder(time[0]+1)).reverse().toString();
				new_min=Integer.parseInt(mins%60)+(hr+1)*60;
			}
		}
		// System.out.println(mins);

		System.out.println(new_min-current);
	}
}


package problems;

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

/**
 * Created by masoud on 6/18/17.
 */
public class Problem419A {
    private static boolean isPalindrome(String str){
        int i = 0, j = str.length()-1;
        while(i < j){
            if (str.charAt(i) != str.charAt(j))
                return false;
            i++;
            j--;
        }
        return true;
    }
    private static String makeString(int time){
        String ret = "";
        if (time < 10)
            ret+="0";
        return (ret+time);
    }
    private static String walkString(String curTime){
        String hourStr = curTime.substring(0, 2);
        String minuteStr = curTime.substring(3);
        int newMinute = Integer.parseInt(minuteStr) + 1;
        int newHour = Integer.parseInt(hourStr);
        if (newMinute == 60){
            newMinute = 0;
            newHour = (newHour+1)%24;
        }
        return makeString(newHour)+":"+makeString(newMinute);
    }
    public static void main(String [] args) {
        String str;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            str = reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        int count = 0;
        while(!isPalindrome(str)){
            str = walkString(str);
            count++;
        }
        System.out.println(count);
    }
}


public class JavaApplication8 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
         String x = in.next();
         String []time = x.split(":");
         String t = new StringBuffer(time[0]).reverse().toString();
         if(time[0].charAt(0) == time[1].charAt(1) && time[0].charAt(1) == time[1].charAt(0))
             System.out.println(0);
         else if(Integer.parseInt(time[1]) < Integer.parseInt(t))
                System.out.println(Integer.parseInt(t) - Integer.parseInt(time[1]));
         else{
             int plus_m = Integer.parseInt(time[0]) + 1 == 24 ? 0 : Integer.parseInt(time[0]) + 1 ;
             String s = new StringBuffer(Integer.toString(plus_m)).reverse().toString();
             System.out.println((60-Integer.parseInt(time[1])) + Integer.parseInt(s));
         }
     }

}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class cf_816a{
        static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
        /*
            Added by me.
        */
        public String readWord() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == ' ' || c=='\n') //care ADD ANY WHITESPACE CHAR??
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

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

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

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

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

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

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

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    } //static class Reader

    public static void main(String[] args) throws IOException{
        Reader s = new Reader(); //Initialize a reader!
        boolean DEB = false;
        StringBuilder in = new StringBuilder(s.readWord());
        int h = Integer.parseInt(in.substring(0, 2));
        int m  = Integer.parseInt(in.substring(3, 5));
        StringBuilder rev2 = new StringBuilder(in);
        StringBuilder rev = rev2.reverse();

        int rm = Integer.parseInt(rev.substring(4,6));
        if(DEB) System.out.println(in);
        if(DEB) System.out.println(rev);

        if((in.toString()).equals(rev.toString())) System.out.println("0");
        else if(h<5){ // h==0,1,...4

            if(m <= rm) System.out.println(rm-m);
            else System.out.println(rm-m+60+10);
        }
        else if(h==5){
            if(m <= rm) System.out.println(rm-m);
            else System.out.println(240+60-m+1);
        }
        else if(h>=6 && h<10){
            System.out.println((9-h)*60 + 61 - m);
        }
        else if(h<15){
            if(m <= rm) System.out.println(rm-m);
            else System.out.println(rm-m+60+10);
        }
        else if(h==15){
            if(m <= rm) System.out.println(rm-m);
            else System.out.println(240+60-m+2);
        }
        else if(h<20){
            System.out.println((19-h)*60 + 62 - m);
        }
        else if(h < 23){
            if(m < =rm) System.out.println(rm-m);
            else System.out.println(rm-m+60+10);
        }
        else if(h==23){
            if(m <= rm) System.out.println(rm-m);
            else System.out.println(60 - m);
        }

    } //main

} //public class Contest


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

public class CF513B {

    public static void solve(Input in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        long k = in.nextLong() - 1;
        int[] ans = new int[n];
        int from = 0;
        int j = n;
        for (int i = 0; from < n; ++i) {
            while (from < n - 1 && k >= 1L << (n - from - 2)) {
                k -= 1L << (n - from - 2);
                ans[--j] = from++;
            }
            ans[i] = from;
            from++;
        }
        for (int i = 0; i < n; ++i) {
            out.print((ans[i] + 1) + " ");
        }
        out.println();
        rec(0, 0, new int[n]);
    }

    private static void rec(int it, int mask, int[] p) {
        if (it == p.length) {
            int sum = 0;
            for (int i = 0; i < p.length; ++i) {
                int v = p[i];
                for (int j = i; j < p.length; ++j) {
                    v = Math.min(v, p[j]);
                    sum += v;
                }
            }
            System.err.println(Arrays.toString(p) + " " + sum);
            return;
        }
        for (p[it] = 0; p[it] < p.length; ++p[it]) {
            if ((mask & (1 << p[it])) == 0) {
                rec(it + 1, mask | (1 << p[it]), p);
            }
        }
    }

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

    static class Input {
        BufferedReader in;
        StringBuilder sb = new StringBuilder();

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

        public Input(String s) {
            this.in = new BufferedReader(new StringReader(s));
        }

        public String next() throws IOException {
            sb.setLength(0);
            while (true) {
                int c = in.read();
                if (c == -1) {
                    return null;
                }
                if (" \n\r\t".indexOf(c) == -1) {
                    sb.append((char)c);
                    break;
                }
            }
            while (true) {
                int c = in.read();
                if (c == -1 || " \n\r\t".indexOf(c) != -1) {
                    break;
                }
                sb.append((char)c);
            }
            return sb.toString();
        }

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

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

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


import java.util.List;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

class TaskB1 {

    public static long counter = 0;
    public static int n;
    public static long m;

    public void find(Integer i, PrintWriter out, ArrayList<Integer> left, ArrayList<Integer> right) {
        left.add(i);
        if(i == n || counter >= m) {
            counter++;
            if(counter == m) {
                for(Integer j : left) {
                    out.print(j + " ");
                }
                List<Integer> reversed = (ArrayList<Integer>)right.clone();
                Collections.reverse(reversed);
                for(Integer j : reversed) {
                    out.print(j + " ");
                }
                out.println();
            }
            return;
        }
        for(Integer j = i + 1; j <= n; j++) {
            find(j, out, left, right);
            left.remove(j);
            right.add(j);
        }
        for(Integer j = n; j > i; j--) {
            right.remove(j);
        }
        left.remove(i);
    }

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextLong();

        ArrayList<Integer> left = new ArrayList<Integer>();
        ArrayList<Integer> right = new ArrayList<Integer>();
        for(Integer i = 1; i <= n; i++) {
            find(i, out, left, right);
            right.add(i);
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;

/*
public class _512A {

}

 */

public class _513B {
	public void solve() throws FileNotFoundException {
		InputStream inputStream = System.in;

		InputHelper inputHelper = new InputHelper(inputStream);

		PrintStream out = System.out;

		//actual solution
		int n = inputHelper.readInteger();
		int m = inputHelper.readInteger();

		Deque<Integer> p = new ArrayDeque<Integer>();

		p.add(n);

		m--;
		for(int i = n - 1, j = 0; i >= 1; i--, j++)
		{
			if((m & (1L << j)) == (1L << j))
			{
				p.addLast(i);
			}
			else
			{
				p.addFirst(i);
			}
		}

		for (Integer i : p) {
			System.out.print(i + " ");
		}
		System.out.println();
		//end here
	}

	public static void main(String[] args) throws FileNotFoundException {
		(new _513B()).solve();
	}

	class InputHelper {
		StringTokenizer tokenizer = null;
		private BufferedReader bufferedReader;

		public InputHelper(InputStream inputStream) {
			InputStreamReader inputStreamReader = new InputStreamReader(
					inputStream);
			bufferedReader = new BufferedReader(inputStreamReader, 16384);
		}

		public String read() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					String line = bufferedReader.readLine();
					if (line == null) {
						return null;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return tokenizer.nextToken();
		}

		public Integer readInteger() {
			return Integer.parseInt(read());
		}

		public Long readLong() {
			return Long.parseLong(read());
		}
	}
}


import com.github.guliash.math.Helper;

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

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

class TaskE {
    int[] a;
    int n;
    public void solve(int testNumber, Reader in, PrintWriter out) {
        n = in.ni(); int m = in.ni();
        a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = i;
        }
        boolean can = true;
        int max = 0;
        do {
            max = Math.max(max, findF());
        } while(Helper.nextPermutation(a));
        for(int i = 0; i < n; i++) {
            a[i] = i;
        }
        do {
            if(findF() == max) {
                m--;
                if(m == 0) {
                    for(int i = 0; i < n; i++) {
                        out.print((a[i] + 1) + " ");
                    }
                    out.println();
                    return;
                }
            }
        } while(Helper.nextPermutation(a));
    }
    public int findF() {
        int cur = 0;
        for(int i = 0; i < n; i++) {
            for(int j = i; j < n; j++) {
                int min = Integer.MAX_VALUE;
                for(int z = i; z <= j; z++) {
                    min = Math.min(a[z], min);
                }
                cur += min;

            }
        }
        return cur;
    }
}

class Reader {
    private BufferedReader in;
    private StringTokenizer st = new StringTokenizer("");
    private String delim = " ";

    public Reader(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
    }

    public String next() {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(rl());
        }
        return st.nextToken(delim);
    }

    public String rl() {
        try {
            return in.readLine();
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }

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

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

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


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

public class _42_d2_B {

    public void solve() throws Exception {

        String a = nextWord(), b = nextWord();
        int base = 0;
        for (int i=0; i<a.length(); ++i) base = max(base, a.charAt(i)-48);
        for (int i=0; i<b.length(); ++i) base = max(base, b.charAt(i)-48);
        base++;
        int aa = Integer.parseInt(a, base);
        int bb = Integer.parseInt(b, base);
        println(Integer.toString(aa+bb, base).length());

    }

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

    boolean showDebug = true;

    double EPS = 1e-7;
    int INF = Integer.MAX_VALUE;
    long INFL = Long.MAX_VALUE;
    double INFD = Double.MAX_VALUE;

    int absPos(int num) {
        return num<0 ? 0:num;
    }
    long absPos(long num) {
        return num<0 ? 0:num;
    }
    double absPos(double num) {
        return num<0 ? 0:num;
    }

    int min(int... nums) {
        int r = INF;
        for (int i: nums)
            if (i<r) r=i;
        return r;
    }
    int max(int... nums) {
        int r = -INF;
        for (int i: nums)
            if (i>r) r=i;
        return r;
    }
    long minL(long... nums) {
        long r = INFL;
        for (long i: nums)
            if (i<r) r=i;
        return r;
    }
    long maxL(long... nums) {
        long r = -INFL;
        for (long i: nums)
            if (i>r) r=i;
        return r;
    }
    double minD(double... nums) {
        double r = INFD;
        for (double i: nums)
            if (i<r) r=i;
        return r;
    }
    double maxD(double... nums) {
        double r = -INFD;
        for (double i: nums)
            if (i>r) r=i;
        return r;
    }

    long sumArr(int[] arr) {
        long res = 0;
        for (int i: arr)
            res+=i;
        return res;
    }
    long sumArr(long[] arr) {
        long res = 0;
        for (long i: arr)
            res+=i;
        return res;
    }
    double sumArr(double[] arr) {
        double res = 0;
        for (double i: arr)
            res+=i;
        return res;
    }

    long partsFitCnt(long partSize, long wholeSize) {
        return (partSize+wholeSize-1)/partSize;
    }

    boolean odd(long num) {
        return (num&1)==1;
    }

    boolean hasBit(int num, int pos) {
        return (num&(1<<pos))>0;
    }

    long binpow(int a, int n) {
        long r = 1;
        while (n>0) {
            if ((n&1)!=0) r*=a;
            a*=a;
            n>>=1;
        }
        return r;
    }

    boolean isLetter(char c) {
        return (c>='a' && c<='z') || (c>='A' && c<='Z');
    }
    boolean isLowercase(char c) {
        return (c>='a' && c<='z');
    }
    boolean isUppercase(char c) {
        return (c>='A' && c<='Z');
    }
    boolean isDigit(char c) {
        return (c>='0' && c<='9');
    }

    String stringn(String s, int n) {
        if (n<1) return "";
        StringBuilder sb = new StringBuilder(s.length()*n);
        for (int i=0; i<n; ++i) sb.append(s);
        return sb.toString();
    }
    String str(Object o) {
        return o.toString();
    }

    long timer = System.currentTimeMillis();
    void startTimer() {
        timer = System.currentTimeMillis();
    }
    void stopTimer() {
        System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
    }

    class InputReader {
        private byte[] buf;
        private int bufPos = 0, bufLim = -1;
        public InputReader(int size) {
            buf = new byte[size];
        }
        private void fillBuf() throws IOException {
            bufLim = System.in.read(buf);
            bufPos = 0;
        }
        char read() throws IOException {
            if (bufPos>=bufLim) fillBuf();
            return (char)buf[bufPos++];
        }
        boolean hasInput() throws IOException {
            if (bufPos>=bufLim) fillBuf();
            return bufPos<bufLim;
        }
    }

    InputReader inputReader = new InputReader(1<<16);
    static BufferedWriter outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);

    char nextChar() throws IOException {
        return inputReader.read();
    }
    char nextNonWhitespaceChar() throws IOException {
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        return c;
    }
    String nextWord() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        while (c>' ') {
            sb.append(c);
            c = inputReader.read();
        }
        return new String(sb);
    }
    String nextLine() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        while (c!='\n' && c!='\r') {
            sb.append(c);
            c = inputReader.read();
        }
        return new String(sb);
    }
    int nextInt() throws IOException {
        int r = 0;
        char c = nextNonWhitespaceChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r=c-48;
        c = nextChar();
        while (c>='0' && c<='9') {
            r*=10;
            r+=c-48;
            c=nextChar();
        }
        return neg ? -r:r;
    }
    long nextLong() throws IOException {
        long r = 0;
        char c = nextNonWhitespaceChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r = c-48;
        c = nextChar();
        while (c>='0' && c<='9') {
            r*=10L;
            r+=c-48L;
            c=nextChar();
        }
        return neg ? -r:r;
    }
    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextWord());
    }
    int[] nextArr(int size) throws NumberFormatException, IOException {
        int[] arr = new int[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextInt();
        return arr;
    }
    long[] nextArrL(int size) throws NumberFormatException, IOException {
        long[] arr = new long[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextLong();
        return arr;
    }
    double[] nextArrD(int size) throws NumberFormatException, IOException {
        double[] arr = new double[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextDouble();
        return arr;
    }
    String[] nextArrS(int size) throws NumberFormatException, IOException {
        String[] arr = new String[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextWord();
        return arr;
    }
    char[] nextArrCh(int size) throws IOException {
        char[] arr = new char[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextNonWhitespaceChar();
        return arr;
    }
    char[][] nextArrCh(int rows, int columns) throws IOException {
        char[][] arr = new char[rows][columns];
        for (int i=0; i<rows; ++i)
            for (int j=0; j<columns; ++j)
                arr[i][j] = nextNonWhitespaceChar();
        return arr;
    }
    char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {
        char[][] arr = new char[rows+2][columns+2];
        for (int i=1; i<=rows; ++i)
            for (int j=1; j<=columns; ++j)
                arr[i][j] = nextNonWhitespaceChar();
        for (int i=0; i<columns+2; ++i) {
            arr[0][i] = border;
            arr[rows+1][i] = border;
        }
        for (int i=0; i<rows+2; ++i) {
            arr[i][0] = border;
            arr[i][columns+1] = border;
        }
        return arr;
    }

    void printf(String format, Object... args) throws IOException {
        outputWriter.write(String.format(format, args));
    }
    void print(Object o) throws IOException {
        outputWriter.write(o.toString());
    }
    void println(Object o) throws IOException {
        outputWriter.write(o.toString());
        outputWriter.newLine();
    }
    void print(Object... o) throws IOException {
        for (int i=0; i<o.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(o[i].toString());
        }
    }
    void println(Object... o) throws IOException {
        print(o);
        outputWriter.newLine();
    }
    void printn(Object o, int n) throws IOException {
        String s = o.toString();
        for (int i=0; i<n; ++i) {
            outputWriter.write(s);
            if (i!=n-1) outputWriter.write(' ');
        }
    }
    void printnln(Object o, int n) throws IOException {
        printn(o, n);
        outputWriter.newLine();
    }
    void printArr(int[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Integer.toString(arr[i]));
        }
    }
    void printArr(long[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Long.toString(arr[i]));
        }
    }
    void printArr(double[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Double.toString(arr[i]));
        }
    }
    void printArr(String[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(arr[i]);
        }
    }
    void printArr(char[] arr) throws IOException {
        for (char c: arr) outputWriter.write(c);
    }
    void printlnArr(int[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(long[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(double[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(String[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(char[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void halt(Object... o) throws IOException {
        if (o.length!=0) println(o);
        outputWriter.flush(); outputWriter.close();
        System.exit(0);
    }

    void debug(Object... o) {
        if (showDebug) System.err.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.US);
        new _42_d2_B().solve();
        outputWriter.flush(); outputWriter.close();
    }
}

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

public class _42_d2_B {

    public void solve() throws Exception {

        String a = nextWord(), b = nextWord();
        int base = 0;
        for (int i=0; i<a.length(); ++i) base = max(base, a.charAt(i)-48);
        for (int i=0; i<b.length(); ++i) base = max(base, b.charAt(i)-48);
        base++;
        int aa = Integer.parseInt(a, base);
        int bb = Integer.parseInt(b, base);
        println(Integer.toString(aa+bb, base).length());

    }

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

    boolean showDebug = true;

    double EPS = 1e-7;
    int INF = Integer.MAX_VALUE;
    long INFL = Long.MAX_VALUE;
    double INFD = Double.MAX_VALUE;

    int absPos(int num) {
        return num<0 ? 0:num;
    }
    long absPos(long num) {
        return num<0 ? 0:num;
    }
    double absPos(double num) {
        return num<0 ? 0:num;
    }

    int min(int... nums) {
        int r = INF;
        for (int i: nums)
            if (i<r) r=i;
        return r;
    }
    int max(int... nums) {
        int r = -INF;
        for (int i: nums)
            if (i>r) r=i;
        return r;
    }
    long minL(long... nums) {
        long r = INFL;
        for (long i: nums)
            if (i<r) r=i;
        return r;
    }
    long maxL(long... nums) {
        long r = -INFL;
        for (long i: nums)
            if (i>r) r=i;
        return r;
    }
    double minD(double... nums) {
        double r = INFD;
        for (double i: nums)
            if (i<r) r=i;
        return r;
    }
    double maxD(double... nums) {
        double r = -INFD;
        for (double i: nums)
            if (i>r) r=i;
        return r;
    }

    long sumArr(int[] arr) {
        long res = 0;
        for (int i: arr)
            res+=i;
        return res;
    }
    long sumArr(long[] arr) {
        long res = 0;
        for (long i: arr)
            res+=i;
        return res;
    }
    double sumArr(double[] arr) {
        double res = 0;
        for (double i: arr)
            res+=i;
        return res;
    }

    long partsFitCnt(long partSize, long wholeSize) {
        return (partSize+wholeSize-1)/partSize;
    }

    boolean odd(long num) {
        return (num&1)==1;
    }

    boolean hasBit(int num, int pos) {
        return (num&(1<<pos))>0;
    }

    long binpow(int a, int n) {
        long r = 1;
        while (n>0) {
            if ((n&1)!=0) r*=a;
            a*=a;
            n>>=1;
        }
        return r;
    }

    boolean isLetter(char c) {
        return (c>='a' && c<='z') || (c>='A' && c<='Z');
    }
    boolean isLowercase(char c) {
        return (c>='a' && c<='z');
    }
    boolean isUppercase(char c) {
        return (c>='A' && c<='Z');
    }
    boolean isDigit(char c) {
        return (c>='0' && c<='9');
    }

    String stringn(String s, int n) {
        if (n<1) return "";
        StringBuilder sb = new StringBuilder(s.length()*n);
        for (int i=0; i<n; ++i) sb.append(s);
        return sb.toString();
    }
    String str(Object o) {
        return o.toString();
    }

    long timer = System.currentTimeMillis();
    void startTimer() {
        timer = System.currentTimeMillis();
    }
    void stopTimer() {
        System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
    }

    class InputReader {
        private byte[] buf;
        private int bufPos = 0, bufLim = -1;
        public InputReader(int size) {
            buf = new byte[size];
        }
        private void fillBuf() throws IOException {
            bufLim = System.in.read(buf);
            bufPos = 0;
        }
        char read() throws IOException {
            if (bufPos>=bufLim) fillBuf();
            return (char)buf[bufPos++];
        }
        boolean hasInput() throws IOException {
            if (bufPos>=bufLim) fillBuf();
            return bufPos<bufLim;
        }
    }

    InputReader inputReader = new InputReader(1<<16);
    static BufferedWriter outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);

    char nextChar() throws IOException {
        return inputReader.read();
    }
    char nextNonWhitespaceChar() throws IOException {
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        return c;
    }
    String nextWord() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        while (c>' ') {
            sb.append(c);
            c = inputReader.read();
        }
        return new String(sb);
    }
    String nextLine() throws IOException {
        StringBuilder sb = new StringBuilder();
        char c = inputReader.read();
        while (c<=' ') c=inputReader.read();
        while (c!='\n' && c!='\r') {
            sb.append(c);
            c = inputReader.read();
        }
        return new String(sb);
    }
    int nextInt() throws IOException {
        int r = 0;
        char c = nextNonWhitespaceChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r=c-48;
        c = nextChar();
        while (c>='0' && c<='9') {
            r*=10;
            r+=c-48;
            c=nextChar();
        }
        return neg ? -r:r;
    }
    long nextLong() throws IOException {
        long r = 0;
        char c = nextNonWhitespaceChar();
        boolean neg = false;
        if (c=='-') neg=true;
        else r = c-48;
        c = nextChar();
        while (c>='0' && c<='9') {
            r*=10L;
            r+=c-48L;
            c=nextChar();
        }
        return neg ? -r:r;
    }
    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextWord());
    }
    int[] nextArr(int size) throws NumberFormatException, IOException {
        int[] arr = new int[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextInt();
        return arr;
    }
    long[] nextArrL(int size) throws NumberFormatException, IOException {
        long[] arr = new long[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextLong();
        return arr;
    }
    double[] nextArrD(int size) throws NumberFormatException, IOException {
        double[] arr = new double[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextDouble();
        return arr;
    }
    String[] nextArrS(int size) throws NumberFormatException, IOException {
        String[] arr = new String[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextWord();
        return arr;
    }
    char[] nextArrCh(int size) throws IOException {
        char[] arr = new char[size];
        for (int i=0; i<size; ++i)
            arr[i] = nextNonWhitespaceChar();
        return arr;
    }
    char[][] nextArrCh(int rows, int columns) throws IOException {
        char[][] arr = new char[rows][columns];
        for (int i=0; i<rows; ++i)
            for (int j=0; j<columns; ++j)
                arr[i][j] = nextNonWhitespaceChar();
        return arr;
    }
    char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {
        char[][] arr = new char[rows+2][columns+2];
        for (int i=1; i<=rows; ++i)
            for (int j=1; j<=columns; ++j)
                arr[i][j] = nextNonWhitespaceChar();
        for (int i=0; i<columns+2; ++i) {
            arr[0][i] = border;
            arr[rows+1][i] = border;
        }
        for (int i=0; i<rows+2; ++i) {
            arr[i][0] = border;
            arr[i][columns+1] = border;
        }
        return arr;
    }

    void printf(String format, Object... args) throws IOException {
        outputWriter.write(String.format(format, args));
    }
    void print(Object o) throws IOException {
        outputWriter.write(o.toString());
    }
    void println(Object o) throws IOException {
        outputWriter.write(o.toString());
        outputWriter.newLine();
    }
    void print(Object... o) throws IOException {
        for (int i=0; i<o.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(o[i].toString());
        }
    }
    void println(Object... o) throws IOException {
        print(o);
        outputWriter.newLine();
    }
    void printn(Object o, int n) throws IOException {
        String s = o.toString();
        for (int i=0; i<n; ++i) {
            outputWriter.write(s);
            if (i!=n-1) outputWriter.write(' ');
        }
    }
    void printnln(Object o, int n) throws IOException {
        printn(o, n);
        outputWriter.newLine();
    }
    void printArr(int[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Integer.toString(arr[i]));
        }
    }
    void printArr(long[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Long.toString(arr[i]));
        }
    }
    void printArr(double[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(Double.toString(arr[i]));
        }
    }
    void printArr(String[] arr) throws IOException {
        for (int i=0; i<arr.length; ++i) {
            if (i!=0) outputWriter.write(' ');
            outputWriter.write(arr[i]);
        }
    }
    void printArr(char[] arr) throws IOException {
        for (char c: arr) outputWriter.write(c);
    }
    void printlnArr(int[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(long[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(double[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(String[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void printlnArr(char[] arr) throws IOException {
        printArr(arr);
        outputWriter.newLine();
    }
    void halt(Object... o) throws IOException {
        if (o.length!=0) println(o);
        outputWriter.flush(); outputWriter.close();
        System.exit(0);
    }

    void debug(Object... o) {
        if (showDebug) System.err.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.US);
        new _42_d2_B().solve();
        outputWriter.flush(); outputWriter.close();
    }
}


import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[])throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		String s1=st.nextToken(),s2=st.nextToken();
		if(s1.length()<s2.length()){
			String tmp=s1;
			s1=s2;
			s2=tmp;
		}
		int n=s1.length(),m=s2.length(),k=0;
		String s3=s1+s2;
		int m=48;
		for(int i=0;i<s3.length();i++) m=Math.max(m,s3.charAt(i));
		m-=47;
		for(int i=n-1,j=n2-1;i>=0;i--,j--){
			if(j>=0) k=(s1.charAt(i)+s2.charAt(j)+k-96)/m;
			else k=(s1.charAt(i)+k-48)/m;
		}
		System.out.println(n+k);
	}
}


import java.util.Scanner;

public class CF46B {

    /**
     * @param args
     */

    int  getInt(char c){
        return Integer.valueOf(new String(""+c));
    }
    void func(){
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
        int num=Integer.MIN_VALUE;
        for(int i=0;i<a.length();i++){
            num=Math.max(num, getInt(a.charAt(i)));
        }
        for(int i=0;i<b.length();i++){
            num=Math.max(num, getInt(b.charAt(i)));
        }
        num++;
        String res=Integer.toString(Integer.valueOf(a, num)+Integer.valueOf(b, num), num);
        System.out.println(res.length());

    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new CF46B().func();
    }


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

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

            BigInteger a = in.nextBigInteger();
            BigInteger b = in.nextBigInteger();

          a = a.add(b);

        String str = a.toString(2);
       System.out.println(str.length());
      }
   }


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = sc.next().charAt(0);
        char b = sc.next().charAt(0);
        int n = sc.nextInt();

        boolean first = (getIndex(a) + n % 4) % 4 == getIndex(b);
        boolean second = (getIndex(a) + 4 - n % 4) % 4 == getIndex(b);
        if (first && !second) {
            System.out.println("cw");
        } else if (!first && second) {
            System.out.println("ccw");
        } else {
            System.out.println("undefined");
        }
    }

    private static int getIndex(char c) {
        switch (c) {
            case 'v':
                return 0;
            case '<':
                return 1;
            case '^':
                return 2;
            case '>':
                return 3;
            default:
                return 0;
        }
    }
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        char r=scan.next().charAt(0),l=scan.next().charAt(0);
        int n=scan.nextInt(),x,y;
        char a [] = {'v','<','^','>'},b [] = {'v','>','^','<'};
        for (int i=0;i<4;i++){if(a[i]==r)x=i;if(b[i]==r)y=i;}
        if(n%2==0) System.out.print("undefined");
        else if(a[(x+n%4)%4]==l)System.out.print("cw");
        else if (b[(y+n%4)%4]==l)System.out.print("ccw");
    }
}


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

 public class spin{

    public static void main(String[] args) {

        char[] spin=new char[4];
        spin[0]=118;
    spin[1]=60;
    spin[2]=94;
    spin[3]=62;

        FastScanner fi=new FastScanner();
        long n;
        char[] start=fi.next().toCharArray();
        char []end=fi.next().toCharArray();
        n=fi.nextInt();
        int cw,ccw;
        String ans=" ";
        int i,j,k,d;
        int st,en;
        st=en=cw=ccw=0;
        for (i=0;i<4 ;i++ )
        {
            if (start[0]==spin[i]) {
                st=i;
            }
            if (end[0]==spin[i]) {
                en=i;
            }

        }

        if (st < en) {
            d=en-st;

            if ( n>=d &&  ( n-d)%4==0) {
                cw=1;
                ans="cw";
            }

            {
                d=4-d;

                if ( n>=d &&  ( n-d)%4==0) {
                    ccw=1;
                    ans="ccw";
                }

            }

        }

        else if (st >= en) {
            d=st-en;
            if ( n>=d && (n-d)%4==0) {
                ccw=1;
                ans="ccw";
            }

            {
                d=4-d;
                if ( n>=d &&  ( n-d)%4==0) {
                    cw=1;
                    ans="cw";
                }

            }

        }

        if ((cw==1 && ccw==1) || (cw==0 && ccw==0)) {
            ans="undefined";
        }

        System.out.println(ans);

    }

public  class FastScanner
{
    BufferedReader br;
    StringTokenizer st;

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

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

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

}


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

public  class spin{

    public static void main(String[] args) {

        char[] spin=new char[4];
        spin[0]=118;
    spin[1]=60;
    spin[2]=94;
    spin[3]=62;

        FastScanner fi=new FastScanner();
        long n;
        char[] start=fi.next().toCharArray();
        char []end=fi.next().toCharArray();
        n=fi.nextInt();
        int cw,ccw;
        String ans=" ";
        int i,j,k,d;
        int st,en;
        st=en=cw=ccw=0;
        for (i=0;i<4 ;i++ )
        {
            if (start[0]==spin[i]) {
                st=i;
            }
            if (end[0]==spin[i]) {
                en=i;
            }

        }

        if (st < en) {
            d=en-st;

            if ( n>=d &&  ( n-d)%4==0) {
                cw=1;
                ans="cw";
            }

            {
                d=4-d;

                if ( n>=d &&  ( n-d)%4==0) {
                    ccw=1;
                    ans="ccw";
                }

            }

        }

        else if (st >= en) {
            d=st-en;
            if ( n>=d && (n-d)%4==0) {
                ccw=1;
                ans="ccw";
            }

            {
                d=4-d;
                if ( n>=d &&  ( n-d)%4==0) {
                    cw=1;
                    ans="cw";
                }

            }

        }

        if ((cw==1 && ccw==1) || (cw==0 && ccw==0)) {
            ans="undefined";
        }

        System.out.println(ans);

    }

 class FastScanner
{
    BufferedReader br;
    StringTokenizer st;

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

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

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

}


public class Driver {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int [] arr = new int[n];

		for (int i = 0; i < arr.length; i++) {
			arr[i] = in.nextInt();
		}

		System.out.println(maxSS(arr));

		in.close();
	}

	static int maxSS(int [] arr){
		int b = 0, c = 0;
		for (int i = 0; i < arr.length; i++) {
			if(arr[i] > 0)
				b += arr[i];
			else
				c += arr[i];
		}
		return b - c;
	}
}


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

		for (int i = 0; i < arr.length; i++) {
			arr[i] = in.nextInt();
		}

		System.out.println(maxSS(arr));

		in.close();
	}

	static int maxSS(int [] arr){
		int b = 0, c = 0;
		for (int i = 0; i < arr.length; i++) {
			if(arr[i] > 0)
				b += arr[i];
			else
				c += arr[i];
		}
		return b - c;
	}
}


public class partition {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lb = new int[100];
        int[] lc = new int[100];
        for(int i = 0; i < n; i++){
            int k = sc.nextInt();
            if(k<0) lc[i] = k;
            if(k>=0) lb[i] = k;
        }
        int b = 0;
        int c = 0;
        for(int i = 0; i < 100; i++){
            b += lb[i];
            c += lc[i];
        }
        System.out.println(b-c);
    }
}


import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long a = 0;
        long b = 0;
        for(int i = 0; i < n; i++){
            long k = s.nextLong();
            if(k > 0){
                a += k;
            }
            else{
                b += k;
            }
        }
        System.out.println(a - k);
    }
}


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

public class tyler
{
    public static void main(String args[])
    {
       Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 1000000;
        for(int i=0;i<n;i++){
            a[i] =  sc.nextInt();
        }
        for(int i=0;i<n;i++){
            int sum1 = 0;
            int x = i;
            for(int k=0;k<n;k++){
            if(k>=x) sum1 = sum1 + a[k]*x;
            else sum1 = sum1 + a[k]*k;
            }
            sum1 = sum1*4;
            if(sum>sum1) sum = sum1;
        }

        System.out.println(sum);
    }


package helloworld;
import java.io.*;
import java.util.*;

import helloworld.cd.Scanner;
public class Try {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter out =new PrintWriter (System.out);
		int n=sc.nextInt();
		int []a=new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		long min=(long)Double.POSITIVE_INFINITY;
        for(int i=0;i<n;i++) {
        	int y=i; long tr=0;
        	for(int j=0;j<n;j++) {
        		int l=0;
        		int p=1;
        		l=Math.abs(i-j)+j+i;
        		//System.out.println(l);
        		p=a[j]*l*2;
        		tr+=p;
        		//System.out.println(tr+"j");
        	}
        	if(tr<min)
        		min=tr;
        }
        out.println(min);
        out.flush();
	}
	static	class Scanner{
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}
        public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}
        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 void waitForInput() throws InterruptedException {Thread.sleep(3000);}
    }
}


import static java.lang.Math.abs;

public class TheFairNutAndElevator implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        int n = in.ni();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = in.ni();
        }
        int result = Integer.MAX_VALUE;
        for (int start = 1; start <= n; start++) {
            int current = 0;
            for (int i = 1; i <= n; i++) {
                int power = 2 * (abs(start - i) + (i - 1) + (start - 1));
                current += power * x[i - 1];
            }
            if (current < result) {
                result = current;
            }
        }
        out.println(result);
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

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

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

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

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

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

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) throws IOException {
        try (TheFairNutAndElevator instance = new TheFairNutAndElevator()) {
            instance.solve();
        }
    }
}


package test;
public class test {
	public static void main(String args[])
	{
		int n,ans=Integer.MAX_VALUE,liftfloor,k=0;
		int arr[]=new int[105];
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for(int i=1;i<=n;i++)
			arr[i]=sc.nextInt();
		for(int i=1;i<=n;i++)
		{
			liftfloor=i;
			for(int j=1;j<=n;j++)
			{
				k+=2*arr[j]*(Math.abs(liftfloor-j)+(j-1)+liftfloor-1);
			}
			ans=Math.min(ans, k);
			k=0;
		}
		System.out.println(ans);
	}
}


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

public class Solution {

public static void main(String[] args){

   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(1e6);
static final int mxV = (int)(5e5+1), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, y;
static char[]str;
public static void solve() throws Exception {
	   // solve the problem here
		s = new MyScanner();
   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
        int tc = 1;//s.nextInt();
        NumberTheoryUtils ntu = new NumberTheoryUtils();
        while(tc-- > 0){
        	n = s.nextInt();
        	long m = s.nextLong();
        	ntu.setMod(m);
        	long[]fact = ntu.getFactorialsModulo(n+1);
        	long ans = 0;
        	for(int length = 1; length <=n; length++) {
        		// 1 ... n+1-length
        		ans += (((((n+1-length) * fact[length])%m)*fact[n+1-length])%m) ;
        		ans %= m;
        	}
        	if(ans < 0) ans += m;
        	out.println(ans);
        }

        out.flush();
        out.close();
}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() { return Integer.parseInt(next()); }
    long nextLong() { return Long.parseLong(next()); }
    double nextDouble() { return Double.parseDouble(next()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class dagger implements Runnable {
    private static final int INF = (int) 1e9;

    public  void solve() throws IOException
    {

       int n = readInt();
       long m = readLong();

       long fac[]= new long[n+1];
       fac[0]=1;
       for(int i=1;i<=n;i++)
       {
       	fac[i]=(i*fac[i-1])%m;
       }

       long val=0;

       for(long i=1;i<=(long)n;i++){
       	long sum= (n-i+1)*(n-i+1);
       	sum=sum%m;
       	sum  = (sum*fac[(int)i])%m;
       	sum = (sum*fac[(int)(n-i)])%m;
         val = (val+sum)%m;
       }
       out.println(val);

    }

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

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;

    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }

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

    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int u ;
    int v ;
    int val;
    edge(int u1, int v1 , int val1)
    {
       this.u=u1;
       this.v=v1;
       this.val=val1;
    }
    public int compareTo(edge e)
    {
        return this.val-e.val;
    }
}


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

//author : s a n 1 d h y a

//Date : 18-07-2020

public class C1284 {
    static long Mod = 1000000007;

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void sortbyColumn(int arr[][], int col) {
        Arrays.sort(arr, new Comparator<int[]>() {

            @Override
            public int compare(final int[] entry1, final int[] entry2) {

                if (entry1[col] > entry2[col])
                    return 1;
                else
                    return -1;
            }
        });
    }

    public static long modex(long x, long y) {
        x = x % Mod;
        long ret = 1;
        while (y > 0) {
            if (y % 2 != 0) {
                ret = ret * x % Mod;
            }
            x = x * x % Mod;
            y >>= 1;
        }
        return ret;
    }

    public static long mplr(long x, long y) {
        long ret = 0;
        while (y != 0) {
            if (y % 2 != 0) {
                ret = (ret + x) % Mod;
            }
            x = (x + x) % Mod;
            y >>= 1;
        }
        return ret;
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long n=sc.nl();
        long m=sc.nl();
        long f[]=new long[(int)(n+10)];
        f[0]=1;

        //Factorial caluclation upto N
        for(long i=1;i<=n;i++){
            f[(int)i]=((f[(int)(i-1)]%m)*(i%m))%m;
        }

        long sm=0;

    //implementing the formula :
        for(long i=1;i<=n;i++){
            long p=n-i+1;
            long f1=f[(int)(i)];
            long f2=f[(int)(p)];
            sm+=((p%m)*(f1%m)*(f2%m))%m;
        }
        System.out.println(sm%m);
\    }
}


package Hello2020;

import java.util.*;

public class Prob1284C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        long[] factorials = new long[250005];
        factorials[0] = 1;
        for (int i = 1; i <= n; i++) {
            factorials[i] = factorials[i - 1] * i % m;
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += (n - i + 1) * (factorials[i] * factorials[n - i + 1] % m);
            ans %= m;
        }
        System.out.println(ans);
    }
}