import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.InputMismatchException;

public class E {
    final static int MOD = 1000000007;
    static long max = 1;
    static long cap = 1;
    static long[] powOf2 = new long[64];

    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        max = in.nextLong();
        cap = in.nextLong();

        long odd = binarySearchOdd(1,  (max + 1L) / 2L * 2L - 1L);
        long even = binarySearchEven(2, max / 2L * 2L);
        long res = Math.max(odd, even);
        System.out.println(res);
    }

    private static long binarySearchEven(long min, long max) {
        if (max == min + 2L) {
            if (countEven(min) >= cap) {
                return min;
            } else {
                return -1;
            }
        }
        long avg = (max + min) / 2L;
        if (avg % 2 == 1) avg--;
        long countAvg = countEven(avg);
        if (countAvg < cap) {
            return binarySearchEven(min, avg);
        } else {
            return binarySearchEven(avg, max);
        }
    }

    private static long binarySearchOdd(long min, long max) {
        if (max == min + 2L) {
            if (countOdd(min) >= cap) {
                return min;
            } else {
                return -1;
            }
        }
        long avg = (max + min) / 2L;
        if (avg % 2 == 0) avg--;
        long countAvg = countOdd(avg);
        if (countAvg < cap) {
            return binarySearchOdd(min, avg);
        } else {
            return binarySearchOdd(avg, max);
        }
    }

    private static long countEven(long n) {
        long k = n / 2L;
        double mDouble = log2((double)max / (double)k);
        long m = (long) mDouble;
        long count = 0;
        for (int i = 1; i <= m; i++) {
            count += powOf2(i);
        }
        long endLevelM = powOf2(m) * k + powOf2(m) - 1;
        long lackLevelM = 0;
        if (max < endLevelM) {
            lackLevelM = Math.min(endLevelM - max, powOf2(m));
        }
        return count - lackLevelM;
    }

    private static long countOdd(long n) {
        if (n == 1) return max;
        long k = (n - 1L) / 2L;
        double mDouble = 1 + log2((double)max / ((double)k + 1D));
        long m = (long) mDouble;
        long count = 0;
        for (int i = 1; i <= m; i++) {
            count += powOf2(i - 1L);
        }
        long endLevelM = powOf2(m) * k + powOf2(m) - 1;
        long lackLevelM = 0;
        if (max < endLevelM) {
            lackLevelM = Math.min(endLevelM - max, powOf2(m - 1));
        }
        return count - lackLevelM;
    }

    private static long powOf2(long n) {
        if (powOf2[(int)n] == 0) {
            long res = 1;
            for (int i = 0; i < n; i++) {
                res *= 2L;
            }
            powOf2[(int)n] = res;
        }
        return powOf2[(int)n];
    }

    private static double log2(double x) {
        double log2 = Math.log(2);
        double logx = Math.log(x);
        return logx / log2;
    }

    static class FastReader {
        private boolean finished = false;

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

        public FastReader(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 peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                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 == ',') {
                    c = read();
                }
                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 String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String nextLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        public String nextLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines) {
                return nextLine();
            } else {
                return readLine0();
            }
        }

        public BigInteger nextBigInteger() {
            try {
                return new BigInteger(nextString());
            } catch (NumberFormatException e) {
                throw new InputMismatchException();
            }
        }

        public char nextCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean isExhausted() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1)
                read();
            return value == -1;
        }

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

        public SpaceCharFilter getFilter() {
            return filter;
        }

        public void setFilter(SpaceCharFilter filter) {
            this.filter = filter;
        }

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


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

// author @mdazmat9
public class codeforces{
  static   HashSet set=new HashSet();
  static  int a,b,c;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int test = 1;
        for (int ind = 0; ind < test; ind++) {
             a=sc.nextInt();
             b=sc.nextInt();
              c=sc.nextInt();
            recursion(a,b,c);
            if(set.contains(true)){
                out.println("Yes");
            }
            else
                out.println("No");

        }
        out.flush();
    }
    static void recursion(int x,int y,int z){
     //   System.out.println(x+" "+y+" "+z);
        if(x==c || y==c || x+y==c){
            set.add(true);
            return;
        }
        if(x+y>c)
            return;
            recursion(x+a,y,z);
            recursion(x,y+b,z);

    }

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

}
class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;

    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }

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

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

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

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

class OutputWriter {
    BufferedWriter writer;

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

    public void print(int i) throws IOException {
        writer.write(i);
    }

    public void print(String s) throws IOException {
        writer.write(s);
    }

    public void print(char[] c) throws IOException {
        writer.write(c);
    }

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

}


import java.util.Scanner;

public class 978A {

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

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

		for (int i = 0; i < arr.length; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] == arr[j]) {
					arr[i] = 0;
				}
			}
		}

		System.out.println(arr.length);
		for (int i = 0; i < arr.length; i++)
			if (arr[i] != 0)
			  System.out.print(arr[i] + " ");
		sc.close();
	}

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Vadim
 */
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();
	}
}

class TaskC {
    long a[] = new long[17];
    HashMap<Long, Long> cache = new HashMap<Long, Long>();

    private long calc(long n) {
        if(n==0) {
            return 0;
        }
        if(cache.containsKey(n)){
            return cache.get(n);
        }
        for (int i = 0; i < 17; i++) {
            if(a[i] >= n) {
                if(a[i] == n) {
                    cache.put(n, (long)i+1);
                    return i+1;
                }

                long k = n/a[i-1];
                long c1 = i*k + calc(n-a[i - 1]*k);

                k = (a[i]-n)/a[i-1];
                long c2 = i + 1 + i*k+ calc(a[i]-a[i-1]*k-n);

                long min = Math.min(c1, c2);
                cache.put(n, min);
                return min;
            }
        }
        throw new RuntimeException();
    }

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

        a[0] = 1;
        for (int i = 1; i < 17; i++) {
            a[i] = a[i-1]*10 + 1;
        }

        out.println(calc(n));

    }
}

class InputReader  extends BufferedReader {
    public InputReader(InputStream st) {
        super(new InputStreamReader(st));
    }

    public int nextInt() {
        try {
            int c = read();

            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new RuntimeException();
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

}


import java.math.*;
import java.util.*;
public class Main {

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

		String array[]=new String[12];

		array[0]="January";
		array[1]="February";
		array[2]="March";
		array[3]="April";
		array[4]="May";
		array[5]="June";
		array[6]="July";
		array[7]="August";
		array[8]="September";
		array[9]="October";
		array[10]="November";
		array[11]="December";
		int x=0;
		String data=in.nextLine();
		String y=in.nextLine();
		int z=Integer.parseInt(y);
		for(int i=0;i<array.length;i++){
			if(array[i].equals(data)){
				x=i+1;
				break;
			}
		}
		x=x+z;
		x=x%12;
		if(x==0 && !data.equals("September"))
			System.out.println(data);

		if(x==0 && data.equals("September")){
			System.out.println("December");
		}
		else
		System.out.println(array[x-1]);

	}

}


import java.util.*;

public class Solution {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    StringBuilder res = new StringBuilder();
    char[] s = sc.next().toCharArray();
    for (int i = 0; i < s.length / 2; i++) {
      res.append(s[s.length - i - 1]).append(s[i]);
    }
    if (s.length % 2 != 0) {
      res.append(s[s.length / 2]);
    }
    System.out.println(res.reverse().toString());
  }
}


import java.util.*;
import java.util.Collections;
public class JavaApplication7 {
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          int[] arr = new int[13];
          arr[1]=31;
          arr[2]=28;
          arr[3]=31;
          arr[4]=30;
          arr[5]=31;
          arr[6]=30;
          arr[7]=31;
          arr[8]=31;
          arr[9]=30;
          arr[10]=31;
          arr[11]=30;
          arr[12]=31;
          int n =input.nextInt();
          String answer = "Yes";
          String entry ="";

          for(int i=0;i<n;i++)
          {
                 int x =input.nextInt();
                 if(x==29) arr[2]=29;
                 entry += x+" ";
          }
          String months = arr[1]+" "+arr[2]+" "+arr[3]+" "+arr[4]+" "+arr[5]+" "+arr[6]+" "+arr[7]+" "+arr[8]+" "+arr[9]+" "+arr[10]+" "+arr[11]+" "+arr[12]+" ";
          boolean found = months.contains(entry);

          if(found)System.out.println("Yes");
          else{
                for(int i=1;i<=n;i++)
                    months+=months;

                found = months.contains(entry);

          if(found)System.out.println("Yes");
          else System.out.println("No");

          }
      }}


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

public class BurningMidnightOil {
    public static int min=Integer.MAX_VALUE;
    public static int getSum(int v,int k){
        int sum=v;
        int c=1;
        while (v>0){
            v= (int) (v/(Math.pow(k,c)));
            sum+=v;
        }
        return sum;
    }
    public static void bs(int arr[],int start,int end,int key,int k){
        if(start>=end){
            int temp=arr[start];
            temp=getSum(temp,k);
            if(temp>=key && arr[start]<min){
                min=arr[start];
            }
            return;
        }
        int mid=start+(end-start)/2;
        int temp=getSum(arr[mid],k);
        if(temp>=key && arr[start]<min){
            min=arr[mid];
            bs(arr,start,mid-1,key,k);
        }
        else{
            if(temp<key)
                bs(arr,mid+1,end,key,k);
        }
    }
    public static void main(String []args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int k=Integer.parseInt(st.nextToken());
        int []arr= new int[n-n/k];
        int c=0;
        for (int i = n/k+1; i <n ; i++) {
            arr[c]=i;
            c++;
        }
        if(n==1){
            System.out.println(1);
        }else {
            bs(arr, 0, arr.length - 1, n, k);
            System.out.println(min);
        }
    }
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		PrintWriter pr = new PrintWriter(System.out, true);
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		// Scanner s = new Scanner(System.in);
		StringTokenizer st = new StringTokenizer(in.readLine());
		int r1 = Integer.parseInt(st.nextToken());
		int r2 = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(in.readLine());
		int c1 = Integer.parseInt(st.nextToken());
		int c2 = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(in.readLine());
		int d1 = Integer.parseInt(st.nextToken());
		int d2 = Integer.parseInt(st.nextToken());
		for(int i = 1;i <= 9;i++) {
			for(int j = 1;j <= 9;j++) {
				for(int k = 1;k <= 9;k++) {
					for(int m = 1;m <= m;i++) {
						if((i == j) || (i == k) || (i == m) || (j == k) || (j == m) || (k == m)) continue;
						if(i+j == r1 && k+m == r2 && i+k == c1 && m+j == c2 && i+m == d1 && k+j == d2) {
							pr.println(i+" "+j);
							pr.println(k+" "+m);
							return;
						}
					}
				}
			}

		}
	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
//public
class A2OJ_L4  {

    Reader sc;
    PrintWriter out;

    void solve() throws IOException{
        int n = sc.nextInt();
        int m = sc.nextInt();
        int i1 = sc.nextInt()-1;
        int j1 = sc.nextInt()-1;
        int a = sc.nextInt();
        int b = sc.nextInt();

        int[][] g = new int[n][m];
        for(int i=0;i<n;i++){
            Arrays.fill(g[i],Integer.MAX_VALUE-10);
        }

        int[] dira = {-a,a,-a,a};
        int[] dirc = {-b,-b,b,b};

        g[i1][j1]=0;
        Queue<Integer> q = new LinkedList<>();
        q.add(i1);
        q.add(j1);
        int x,y,tx,ty;
        while (!q.isEmpty()){
            x = q.poll();
            y = q.poll();
            int val = g[x][y];
            for(int j=0;j<4;j++){
                tx = x+dira[j];
                ty = y+dirc[j];
                if(tx>=0 && ty>=0 &&tx<n && ty<m && g[tx][ty]>1+val){
                    g[tx][ty]=1+val;
                    q.add(tx);q.add(ty);
                }
            }
        }

        int ans = Integer.MAX_VALUE-10;
        ans = Math.min(ans,g[0][0]);
        ans = Math.min(ans,g[0][m-1]);
        ans = Math.min(ans,g[n-1][0]);
        ans = Math.min(ans,g[n-1][m-1]);

        if(ans==Integer.MAX_VALUE-10){
            out.println("Poor Inna and pony!");
        }else{
            out.println(ans);
        }

    }

    void runIO() throws Exception{
        sc = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws Exception{
        new A2OJ_L4().runIO();
    }
    //fast reader
    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];int cnt=0,c;while((c=read())!=-1){if(c=='\n')
            break;buf[cnt++]=(byte)c;}
            return new String(buf,0,cnt);}
        public int nextInt()throws IOException{int ret=0;byte c=read();while(c<=' ')
            c=read();boolean neg=(c=='-');if(neg)
            c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)
            return-ret;return ret;}
        public long nextLong()throws IOException{long ret=0;byte c=read();while(c<=' ')
            c=read();boolean neg=(c=='-');if(neg)
            c=read();do{ret=ret*10L+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 String next()throws IOException{StringBuilder sb=new StringBuilder();byte c;while((c=read())<=' ');do{sb.append((char)c);}while((c=read())>' ');return sb.toString();}
        public int nextInt2()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 void close()throws IOException{if(din==null)
            return;din.close();}}

}


import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		String aux1 = scan.nextLine();
		char p[] = aux1.toCharArray();
		String aux = "";
		for (int i = p.length-1; i >=0; i--) {
			aux = aux+p[i];
		}

		int binario=Integer.parseInt(aux);
		int decimal=0,base=0;
		do{
		if(binario%10==1){
		decimal+=(int)Math.pow(2,base);
		}
		binario=binario/10;
		base+=1;
		}while(binario!=1);
		decimal+=(int)Math.pow(2,base);

		 decimal+=1;
		String binari = "";
		while ( decimal > 0 ) {
		binari = binari + decimal % 2 ;
		decimal /= 2;
		}

		String binary = "";
		for (int i = 0; i < binari.length(); i++) {
			binary = binary +(binari.charAt(i));
		}
		for (int i = 0; i < n-binari.length(); i++) {
			binary = binary +(0);
		}

		int sum = 0;
		for (int i = 0; i < n; i++) {
			if(binary.charAt( i) != aux1.charAt(i))
				sum++;
		}
		System.out.println(sum);
	}
}


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

public class sol{
    public static void main(String args[]){
        Scanner in= new Scanner(System.in);
        int n,b,g;
        b=in.nextInt();
        g=in.nextInt();
        n=in.nextInt();
        if(b>=n&&g>=n){
            System.out.println(n+1);
        }else if(b>=n&&g<n){
            System.out.println(n+1-(n-g));
        }else if(b<n&&g>=n){
            System.out.println(n+1-(n-b));
        }else if(b<n&&g<n){
            System.out.println(n+1-((n-g)+(n-b)));
        }


import java.util.*;

public final class Hello5
{
public static void main(String[] args) throws java.lang.Exception
{
    Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(LastDigit(a,b));
}

public static int LastDigit(int a, int b) {
    int k,f=1;
    if(b==0)
        return 1;
    else {
        k=b%4;
        if(k==0)
            b=4;
        else
            b=k;
        for(int i=0;i<b;i++)
            f=f*a;

          //return f;
        return(f%10);
    }
}
}


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

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

    static class TaskB {
        final String[] types = new String[]{"2-type", "3-type", "11-type", "6-type", "7-type"};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int base = in.nextInt(), number = in.nextInt();
            if (check2(base, number) != -1) {
                out.println(types[0]);
                out.println(check2(base, number));
                return;
            }

            if (base % number == 1) {
                out.println(types[1]);
                return;
            }

            if ((base + 1) % number == 0) {
                out.println(types[2]);
                return;
            }

            if (!check6(base, number)) {
                out.println(types[3]);
                return;
            }

            out.println(types[4]);
        }

        private int check2(int n, int m) {
            List<Pairii> divs = new ArrayList<>();
            for (int i = 2; i <= m; ++i) {
                if (m % i == 0) {
                    int k = 0;
                    while (m % i == 0) {
                        m /= i;
                        k++;
                    }
                    divs.add(new Pairii(i, k));
                }
            }

            int ans = 0;
            for (Pairii p : divs) {
                if (n % p.first != 0)
                    return -1;

                int cnt = 0;
                while (n % p.first == 0) {
                    cnt++;
                    n /= p.first;
                }

                ans = Math.max(ans, (p.second + cnt - 1) / cnt);
            }

            return ans;
        }

        private boolean check2_3_11(int base, int number) {
            if (check2(base, number) != -1) {
                return true;
            }

            if (base % number == 1) {
                return true;
            }

            if ((base + 1) % number == 0) {
                return true;
            }
            return false;
        }

        private boolean check6(int n, int m) {
            for (int i = 2; i <= m; ++i) {
                if (m % i == 0) {
                    while (m % i == 0)
                        m /= i;
                    if (!check2_3_11(n, i)) return false;
                }
            }
            return true;
        }

    }

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

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

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

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

        public String next() {
            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;
        }

    }

    static class Pairii implements Comparable<Pairii> {
        public int first;
        public int second;

        public Pairii() {
        }

        public Pairii(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public int compareTo(Pairii other) {
            if (first != other.first) return first < other.first ? -1 : 1;
            if (second != other.second) return second < other.second ? -1 : 1;
            return 0;
        }

        public boolean equals(Object other) {
            if (!(other instanceof Pairii)) return false;
            return compareTo((Pairii) other) == 0;
        }

        public int hashCode() {
            return first * 31 + second;
        }

    }
}


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

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = true;

	public int[] calc(int x, int d)
	{
		int[] res = new int[2], res2;

		int dd = d, i;
		for (i=1; i<8; i++)
		{
			if (dd % x == 0)
			{
				res[0] = 2;
				res[1] = i;
				return res;
			}
			dd *= d;
		}

		if (d % x == 1)
		{
			res[0] = 3;
			return res;
		}

		if (d % x == x-1)
		{
			res[0] = 11;
			return res;
		}

		i=2;
		int x0 = x;
		while ((x>1)&&(i<x0))
		{
			if (x % i == 0)
			{
				dd=1;
				while (x % i == 0)
				{
					dd *= i;
					x /= i;
				}

				res2 = calc(dd, d);
				if (res2[0]==7)
				{
					out.printf("%d-7\n", dd);

					res[0] = 7;
					return res;
				}
			}

			i++;
		}

		res[0] = x==1 ? 6 : 7;
		return res;
	}

	public void test()
	{
		int b = readInt();
		int x = readInt();

		int[] res = calc(x, b);

		out.printf("%d-type\n", res[0]);
		if (res[0]==2)
		{
			out.println(res[1]);
		}
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

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

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


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

public class Main {

    public static final double EPS = 1e-8;
    private static StreamTokenizer in;
    private static Scanner ins;
    private static PrintWriter out;
    private double p;

    public static void main(String[] args) {
        try {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            ins = new Scanner(System.in);
            out = new PrintWriter(System.out);
            try {
                if (System.getProperty("xDx") != null) {
                    in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
                    ins = new Scanner(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                }
            } catch (Exception e) {
                in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
                ins = new Scanner(System.in);
                out = new PrintWriter(System.out);
            }
            new Main().run();
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private double[][] dp;

    private void run() throws IOException {
        int n = nextInt();
        p = nextDouble();
        int t = nextInt();

        dp = new double[n + 1][t + 1];
        for (int i = 0; i <= n; i++) {
            Arrays.fill(dp[i], -1.0);
        }

        out.printf("%.6f", calcDp(n, t));
    }

    private double calcDp(int n, int t) {
        if (n == 0 || t == 0) {
            return 0;
        }

        if (dp[n][t] >= EPS) {
            return dp[n][t];
        }

        return dp[n][t] = p * (1.0 + calcDp(n - 1, t - 1)) + (1.0 - p) * calcDp(n, t - 1);
    }

    private int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    private long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    private double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }

    private String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

}


package com.animal.demo;import java.util.*;
public class Animal {
    public static void main(String []arg){
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();long ans=0;
        //StringBuilder sb=new StringBuilder();
        long mod=1000000007;
        //System.out.println(qmod(2,3,mod));
        ans=(getc(n+1,mod)-getc(n,mod)+mod)%mod;
        ans=qmod(3,n-1,mod);
        System.out.println(ans);
        //System.out.print(sb);
    }
    static long getc(long n,long mod){
        long res=1;
        long tem=1;
        for(long i=n+1;i<=2*n;i++)
            res=res*i%mod;
        for(int i=1;i<=n;i++)
            tem=tem*i;
        tem=qmod(tem,mod-2,mod);
        res=res*tem%mod*qmod(n+1,mod-2,mod);
        return res%mod;
    }
    static long qmod(long a,long b,long mod){
        long res=1;
        while(b!=0){
            if((b&1)!=0)res=res*a%mod;
            a=a*a%mod;b>>=1;
        }return res;
    }
}


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

import static java.lang.Math.*;

public class Cf182 implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		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 String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		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 double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

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

			return res.toString();
		}

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

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

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Cf182(),"Main",1<<27).start();
	}

	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
	//  array sorting by colm
	static void sortbycolomn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

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

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

	// gcd

	public static long findGCD(long arr[], int n)
	{
		long result = arr[0];
		for (int i = 1; i < n; i++)
			result = gcd(arr[i], result);
		return result;
	}
	// fibonaci
	static int fib(int n)
    {
        int a = 0, b = 1, c;
        if (n == 0)
            return a;
        for (int i = 2; i <= n; i++)
        {
            c = a + b;
            a = b;
            b = c;
        }
        return b;
    }

// sort a string
    public static String sortString(String inputString)
    {

        char tempArray[] = inputString.toCharArray();

        Arrays.sort(tempArray);

        return new String(tempArray);
    }
    static boolean isPowerOfTwo(long n)
    {
        if(n==0)
        return false;

    return (long)(Math.ceil((Math.log(n) / Math.log(2)))) ==
           (long)(Math.floor(((Math.log(n) / Math.log(2)))));
    }
    public static int fun(int l,int r,int k,int[] a)
    {
        if(l<=r)
        {
            if(a[l]<=k && a[r]<=k)
                return 1 + Math.max(fun(l+1,r,k,a),fun(l,r-1,k,a));
            else if(a[l]<=k)
                return 1 + fun(l+1,r,k,a);
            else if(a[r]<=k)
               return 1 + fun(l,r-1,k,a);
            else
                return 0;
        }
        else
            return 0;
    }
	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n];
		for(int i=0;i<n;i++)
		    a[i] = sc.nextInt();
		int ans = fun(0,n-1,k,a);
		System.out.println(ans);
	}
}


import java.util.*;
import java.Math.BigInteger;

public class Solution{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        BigInteger n = new BigInteger(""+sc.nextInt());
        BigInteger temp = n.add(BigInteger.valueOf(1));
        n = n.multiply(temp);
        n = n.multiply(BigInteger.valueOf(3));
        n = n.add(BigInteger.valueOf(1));
        System.out.println(n);
    }
}


import java.util.*;

public class susbus{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int [] numbers = new int[4];
		for (int i=0;i<4;i++) {
			numbers[i] = sc.nextInt();
		}
		int min = Math.min(numbers[0], nums[2]);
		int totmin = Math.min(min, numbers[3]);
		int minasdf = Math.min(numbers[1]-totmin, numbers[2]);
		if (minasdf > 0) {
			System.out.println(256*totmin+32*minasdf);
		}
		else {
			System.out.println(256*totmin);
		}
}
}


import java.util.Scanner;
public class ProblemA {

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

		int length= scan.nextInt();

		int arr[]= new int[length];
		int increase=0, equal=0, decrease=0;

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

		//Tiene que haber caambio en increase, equal pero no en decrease

		//Es decir, se tiene que dejar de incrementar, tiene que dejar de ser constante y nunca debe parar de decrementar

		//Checar que pare de incrementar

		int allequal=0;

		for(int i=0; i< length-1; i++)
		{
			if(arr[i]!=arr[i+1]) {
				allequal=1;

			}

		}

		if(allequal==0) {
			System.out.println("YES");
			System.exit(0);
		}

		int z = 0;

		for(int i=0; i< length-1; i++)
		{
			if(arr[i]>=arr[i+1]) {
				increase=1;
				z=i;
				i=length+1;
			}

		}

		int y=0;

		for(int j=z; j< length-1; j++)
		{
			if(arr[j]!=arr[j+1]) {
				equal=1;
				y=j;

				j=length+1;
			}

		}

		if(increase==1 && equal==0 && decrease==0)
		{
			System.out.println("YES");
			System.exit(0);
		}

		for(int k=y; k< length-1; k++)
		{
			if(arr[k]<=arr[k+1])  decrease=1;

		}

			if(increase==1 && equal==1 && decrease==0)
			{
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

/**
 * Works good for CF
 * @author cykeltillsalu
 */
public class A {

	//some local config
	static boolean test = true;
	static String testDataFile = "test.txt";
	static String feedFile = "feed.txt";
	CompetitionType type = CompetitionType.CF;
	private static String ENDL = "\n";

	// solutions

	private void solve() throws Throwable {
		String s = wread();
		char a = '4';
		char b = '7';
		int count = 0;
		int n = s.length();
		for(int i = 0; i<n; i++){
			if(s.charAt(i) == a || s.charAt(i) == b){
				count++;
			}
		}
		if(count == 4 || count == 7)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

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

		if(test){ //run all cases from testfile:
			BufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));
			String readLine = testdataReader.readLine();
			int casenr = 0;
			out: while (true) {
				BufferedWriter w = new BufferedWriter(new FileWriter(feedFile));
				if(!readLine.equals("input")){
					break;
				}
				while (true) {
					readLine = testdataReader.readLine();
					if(readLine.equals("output")){
						break;
					}
					w.write(readLine + "\n");
				}
				w.close();
				System.out.println("Answer on case "+(++casenr)+": ");

				new A().solve();
				System.out.println("Expected answer: ");

				while (true) {
					readLine = testdataReader.readLine();

					if(readLine == null){
						break out;
					}
					if(readLine.equals("input")){
						break;
					}
					System.out.println(readLine);
				}
				System.out.println("----------------");
			}
			testdataReader.close();
		} else { // run on server
			new A().solve();
		}
		out.close();
	}

	public A() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(feedFile)));
		}
	}

	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	enum CompetitionType {CF, OTHER};
}


import java.util.Scanner;
public class test20{
    public static int testCase20(int n,int k) {

        return 15*n/k+1;
    }
    public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       int t=input.nextInt();
        for (int i = 0; i < t; i++) {
         int n= input.nextInt();
         int k = input.nextInt();
          System.out.println(testCase20(n,k));
        }

    }
}


package second;
import java.util.* ;
import java.lang.Math ;
public class Second {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s=new Scanner(System.in);
        long n,sh;
        n=s.nextLong();
        sh=s.nextLong();
        long r=n*2,g=n*5,b=n*8;
        double a=Math.ceil((double)r/sh)+Math.ceil((double)g/sh)+Math.ceil((double)b/sh);
        System.out.println((int)a);
    }

}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static String fileIn = "Input.txt";
	public static String fileOut = "Output.txt";

	public static String rotate_clockwise(String tmp) {
		return  "" + tmp.charAt(0) +
			tmp.charAt(4) +
			tmp.charAt(1) +
			tmp.charAt(2) +
			tmp.charAt(3) +
			tmp.charAt(5);
	}

	public static String forward(String tmp) {
		return "" + tmp.charAt(2) +
			tmp.charAt(1) +
			tmp.charAt(5) +
			tmp.charAt(3) +
			tmp.charAt(0) +
			tmp.charAt(4);
	}

	public static String left(String tmp) {
		return "" + tmp.charAt(1) +
			tmp.charAt(5) +
			tmp.charAt(2) +
			tmp.charAt(0) +
			tmp.charAt(4) +
			tmp.charAt(3);
	}

	public static String getAllRotationsRepresentator(String tmp) {
		String down_left = left(tmp);
		String down_right =  left(left(left(tmp)));
		String f1 = tmp;
		String f2 = forward(f1);
		String f3 = forward(f2);
		String f4 = forward(f3);
		ArrayList<String> result = new ArrayList<String>();
		for (int i = 0; i < 4; ++i) {
			result.add(down_left);
			result.add(down_right);
			result.add(f1);
			result.add(f2);
			result.add(f3);
			result.add(f4);
			down_left = rotate_clockwise(down_left);
			down_right = rotate_clockwise(down_right);
			f1 = rotate_clockwise(f1);
			f2 = rotate_clockwise(f2);
			f3 = rotate_clockwise(f3);
			f4 = rotate_clockwise(f4);
		}
		Collections.sort(result);
		return result.get(0);

 	}

	public static final String noNext = "-1";
	public static String next(String str) throws Exception {
		if (str.length() == 1 || str.length() == 0) {
			return noNext;
		}
		int n = str.length();
		int i = n - 2;
		char[] s = str.toCharArray();
		while (i >= 0 && s[i] >= s[i + 1]) --i;
		if (i >= 0) {
			int j = i + 1;
			while ( j < n - 1 && s[j + 1] > s[i]) ++j;
			char t = s[i];
			s[i] = s[j];
			s[j] = t;
			for (int k = i + 1; k < i + 1 + (n - i - 1) / 2; k++) {
				t = s[k];
				s[k] = s[(n - 1) - (k - i  - 1)];
				s[(n - 1) - (k - i  - 1)] = t;
			}
			return String.valueOf(s);
		} else {
			return noNext;
		}
	}

	public static ArrayList<String> getAllColoring(String input) throws Exception {
		ArrayList<String> result = new ArrayList<String>();
		String str = new String(input);
		while (str != noNext) {
			result.add(str);
			str = next(str);
		}
		return result;
	}

	public static void main(String[] args) throws Exception {
		PrintWriter jout = new PrintWriter(System.out);
		Scanner jin = new Scanner(new InputStreamReader(System.in));
		//PrintWriter joutf = new PrintWriter(new FileWriter(fileOut));
	//	Scanner jinf = new Scanner(new FileReader(fileIn));

		String input = jin.next();
		HashSet<String> result = new HashSet<String>();
		ArrayList<String> colorings720 = getAllColoring(input);
		for (int i = 0; i < colorings720.size(); ++i) {
			String tmp = getAllRotationsRepresentator(colorings720.get(i));
			result.add(tmp);
		}
		jout.println(result.size());
		//joutf.close();
		jout.close();
	}

}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();

	}

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

	void MagicOut(long X){
		System.err.println(X);
		out.print("1 ");
		char c[] = new char[9];
		for(int v = 8; v >= 0; v--){
			c[v] = (char) ((char) (X % 10) + '0');
			X /= 10;
		}
		out.println(c);
	}
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		long OVER9000 = 1000L*1000L*1000L * 1000L*1000L*1000L;
		System.err.println(OVER9000);
		long a = nextLong();
		long b = nextLong();
		long mod = nextLong();

		HashSet<Long> rem = new HashSet<Long>();
		if(b >= mod)
			out.println("2");
		else{
			a = a * 1000L * 1000 * 1000;
			boolean done = false;
			for(long X = 0, step = 1000L*1000*1000; !done && X / 10 < OVER9000 && X <= a; X += step){
				if(rem.contains(X % mod))
					break;
				rem.add(X % mod);
				if((X % mod) != 0  && X % mod <= (X + b) % mod){
//					System.err.println(X);
					X /= (1000L * 1000 * 1000);
					MagicOut(X);
					done = true;
				}
			}
			if(!done)
				out.println("2");
		}

		in.close();
		out.close();
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class B implements Runnable
{
    String file = "input";

    boolean TEST = false;

    long pow = 1000000000;
    void solve() throws IOException
    {
        long a = nextLong(), b = nextLong(), mod = nextLong();
        boolean[] modA = new boolean[(int)mod];
        long[] minA = new long[(int)mod];
        fill(minA, Long.MAX_VALUE);
        boolean[] modB = new boolean[(int)mod];
        long sa = min(a, mod);
        for(int i = 0; i <= sa; i++)
        {
            int V = (int)(i * pow % mod);
            modA[V] = true;
            minA[V] = min(minA[V], i);
        }
        long sb = min(b, mod);
        for(int i = 0; i <= sb; i++)
        {
            int V = (int)(i % mod);
            modB[V] = true;
        }
        long res = Long.MAX_VALUE;
        for(int i = 0; i < mod; i++)
        {
            int q = (int)((mod - i) % mod);
            if(modA[i] && !modB[q]) res = min(res, minA[i]);
        }
        if(res == Long.MAX_VALUE) out.println(2);
        else
        {
            out.print(1 + " ");
            String s = "" + res;
            while(s.length() < 9) s = "0" + s;
            out.println(s);
        }
    }

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

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

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

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

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

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

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


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

public class Mysterious_strings_April_Fool {

    public static void main(String[]args) throws NumberFormatException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int in = Integer.parseInt(br.readLine());
        System.out.println(in+"");
    }

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public BufferedReader input;
	public PrintWriter output;
	public StringTokenizer stoken = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		new Main();
	}

	Main() throws IOException{
	//	input = new BufferedReader(	new FileReader("input.txt")	);
		input = new BufferedReader(			new InputStreamReader(System.in)	);
		output = new PrintWriter(System.out);
		int n = nextInt();
		String mas [] = new String [41];
		mas[1] = "Washington";
		mas[2] = "Adams";
		mas[3] = "Jefferson";
		mas[4] = "Madison";
		mas[5] = "Monroe";
		mas[6] = "Quincy Adams";
		mas[7] = "Jackson";
		mas[8] = "Van Buren";
		mas[9] = "Harrison";
		mas[10] = "Tyler";
		mas[11] = "Polk";
		mas[12] = "Taylor";
		mas[13] = "Fillmore";
		mas[14] = "Pierce";
		mas[15] = "Buchanan";
		mas[16] = "Lincoln";
		mas[17] = "Johnson";
		mas[18] = "Grant";
		mas[19] = "Hayes";
		mas[20] = "Garfield";
		mas[21] = "Arthur";
		mas[22] = "Cleveland";
		mas[23] = "Harrison";
		mas[24] = "Cleveland";
		mas[25] = "McKinley";
		mas[26] = "Roosevelt";
		mas[27] = "Taft";
		mas[28] = "Wilson";
		mas[29] = "Harding";
		mas[30] = "Coolidge";
		mas[31] = "Hoover";
		mas[32] = "Roosevelt";
		mas[33] = "Truman";
		mas[34] = "Eisenhower";
		mas[35] = "Kennedy";
		mas[36] = "Johnson";
		mas[37] = "Nixon";
		mas[38] = "Ford";
		mas[39] = "Carter";
		mas[40] = "Reagan";

		output.print(mas[n]);

		output.close();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextString());
	}

	private String nextString() throws IOException {
		while (!stoken.hasMoreTokens()){
			String st = input.readLine();
			stoken = new StringTokenizer(st);
		}
		return stoken.nextToken();
	}

}


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

public class Main {

	final static int mod = 1_000_000_007;

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

		STDIN scan = new STDIN();
		int n = scan.nextInt(), m = scan.nextInt();
		int[] dp = new int[n+1];
		dp[1] = 2 % m;
		for(int i = 2; i <= n; i++)
			dp[i] = ((((dp[i-1] + dp[i-1]) % m) + dp[i-1]) % m) + 2;
		System.out.println(dp[n]);
	}

	static class STDIN {
		BufferedReader br;
		StringTokenizer st;

		public STDIN() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

		boolean hasNext() throws Exception {
			if(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.hasMoreTokens();
		}

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

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

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

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

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


/**
 *
 * @author Faruk
 */

import java.util.Arrays;
import java.util.Scanner;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;

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

        int m = scan.nextInt();
        int s = scan.nextInt();
        StringBuilder sb = new StringBuilder();

        if(s > 9*m || s == 0){
            if(m == 1 && s == 0)
                System.out.println("0 0");
            else
                System.out.println("-1 -1");
        }else if(s < m){
            s--;
            int tmp=0;
            while(s>0){
                tmp = s>9?9:s;
                sb.append(tmp);
                s -= tmp;
            }
            for(int i=0; i < m-sb.length(); i++)
                sb.append("0");
            sb.append("1");
            sb.reverse();
            System.out.println(sb + " " + sb);
        }else{
            if((m-1)*9>= s-1){
                sb.append("1");
                s--;
                m--;
            }
            while(s-(m-1)*9 < 10){
                if(s-(m-1)*9<=0){
                    sb.append("0");
                }else{
                    sb.append(s-(m-1)*9);
                    s -= s-(m-1)*9;
                }
                m--;
                if(m==0)
                    break;
            }
            char [] out = sb.toString().toCharArray();
            Arrays.sort(out);
            StringBuilder sb1 = new StringBuilder(new String(out));
            System.out.println(sb.toString() + " " + sb1.reverse().toString());

        }

    }

}


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

public class Prob03 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] L = new int[N];
        int[] R = new int[N];
        for (int i = 0; i < N; i++) {
            L[i] = in.nextInt();
            R[i] = in.nextInt();
        }
        double[] probabilities = new double[11];
        for (int i = 0; i < N; i++) {
            for (int j = L[i]; j <= R[i]; j++) {
                double prob = 1./(R[i]-L[i]+1);
                //count probability j to be the second largest
                double probResult = 0;
                outer:
                for (int k = 0; k < N; k++) {
                    if (i == k) continue;

                    double probMax = (1.*R[k] - j)/(R[k]-L[k]+1);
                    if (probMax < 0) continue;
                    if (i < k && L[k]<=j && R[k] >= j)  probMax += 1./(R[k]-L[k]+1);
                    if (probMax > 1) probMax = 1;

                    for (int m = 0; m < N; m++) {
                        if (m==i || m == k) continue;
                        double probMin = (1.*j - L[m])/(R[m]-L[m]+1);
                        if (probMin < 0) continue outer;
                        if (m < i && L[m]<=j && R[m] >= j)  probMin += 1./(R[m]-L[m]+1);
                        if (probMin > 1) probMin = 1;
//                        System.out.println("second: " + j + " max prob: " + probMax + " min prob: " + probMin);
                        probMax *= probMin;
                    }
                    probResult += probMax;
                }
                prob *= probResult;
                probabilities[j] += prob;
//                System.out.println(Arrays.toString(probabilities));
            }
        }

        double sum = 0;
        double prob = 0;
        for (int i = 1; i < 11; i++) {
            sum += i *probabilities[i];
            prob += probabilities[i];
        }
//        System.out.println(sum);
//        System.out.println(sum / prob);
        System.out.println(String.format("%.9f", sum));
    }

}


import java.util.*;
import java.io.*;
public class Solution{
   public static void main(String args[]){
      Scanner s=new Scanner(System.in);
      char[] str1=s.next().toCharArray();
      char[] str2=s.next().toCharArray();
      for(int i=0;i<str1.length;i++){
         if(str1[i]==str2[i])
         str1[i]='0';
         else
          str1[i]='1';
          System.out.println(str1[i]);
      }
   }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class D262_A {

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

	public static int sum(int n) {
		String str = String.valueOf(n);
		int res = 0;
		for (int i = 0; i < str.length(); i++) {
			res += Integer.valueOf(String.valueOf(str.charAt(i)));
		}
		return res;
	}

	public static int num(int l, int r, int n) {
		while (r - l > 1) {
			int mid = (r+l)/2;
			if (mid == n) return n;
			if (mid > n) r = mid; else l = mid;
		}
		return -1;
	}

	static void solve() throws IOException {
		BufferedReader in;
		PrintWriter out;
		try {
			in = new BufferedReader(new FileReader("are1231a.in"));
			out = new PrintWriter(new File("are2131a.out"));
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		}
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int a = Integer.valueOf(tok.nextToken());
		int b = Integer.valueOf(tok.nextToken());
		int c = Integer.valueOf(tok.nextToken());
		int mas[] = new int[100000000];
		int ind = 0;
		double tmp = 0;
		BigInteger bi;
		int res = 0;
		for (int i = 0; i < 100; i++) {
			bi = new BigInteger(String.valueOf(i));
			res = num(0,1000000000,b*Integer.valueOf(bi.pow(a).toString())+c);
			if (res > 0) {
				mas[ind] = res;
				ind++;
			}
		}

		int cnt = 0;
		for (int i = 0; i < ind; i++) {
			bi = new BigInteger(String.valueOf(sum(mas[i]))).pow(a);
			if(mas[i] == b*Integer.valueOf(String.valueOf(bi.toString()))+c) {
				mas[cnt] = mas[i];
				cnt++;
			}
		}
		System.out.println(cnt+1);
		for (int i = 0; i < cnt; i++) {
			System.out.print(mas[i]+" ");
		}
	}

}


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Solution {

	Scanner in;

	void solve(){

		in = new Scanner(System.in);

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

		int i=0;
		int ans =0;
		while( i < n){

			int ch = str.charAt(i);

			if(ch < 97){
				Set <Integer>st = new HashSet<>();
				for(int j=i;j<n;j++){
					int ch1 = str.charAt(j);
					if(ch1 < 97)
						st.add(ch1);
					else{
						i=j;
						ans = Math.max(ans,st.size());
						break;
					}
				}
			}
			else
				i++;

		}
		System.out.println(ans);

	}

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

}


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

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);

		int x = input.nextInt();
		int y = input.nextInt();
		int n = input.nextInt();
		int[] fib = new int[n+1];
		fib[1] = x;
		fib[2] = y;
		for(int i=3;i<=n;i++){
			fib[i] = fib[i-1] - fib[i-2];
		}
		if(fib[n] < 0)System.out.println((fib[n]+1000000007)%1000000007);
		else
			System.out.println(fib[n]%1000000007);
	}
}


import java.util.Scanner;

public class Main {

    public static int f(int n , int f1 ,int f2 , int[]usingarr){
        usingarr[1] = f1;
        usingarr[2]= f2;
        if (usingarr[n] != -1 || n==1 || n==2 ) return usingarr[n];

        else {
            usingarr[n] =  f(n-1,f1,f2,usingarr) - f(n-2,f1,f2,usingarr);
            return usingarr[n];

        }

    }

    public static void main(String[] args) {

       Scanner input = new Scanner(System.in);
         int x = input.nextInt();
        int y = input .nextInt();
         int b = input.nextInt();
         if (x==0&&y==0) System.out.println(Math.floorMod(0,1000000007));

         else {
          int[]arr = new int[b+1];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = -1 ;

        }

        System.out.println( Math.floorMod(f(b,x,y,arr),1000000007));

    }
    }

}


import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int a = s.nextInt();
        int b = s.nextInt();
        int n = s.nextInt();
        int turn = 0;

        while (n>=0) {
            if(turn%2 == 0) {
                if(n-gcd(a,n) < 0) {
                    System.out.println(turn%2);
                } else {
                    n-=gcd(a,n);
                }
            } else {
                if(n-gcd(b,n) < 0) {
                    System.out.println(turn%2);
                } else {
                    n-=gcd(b,n);
                }

            }

            turn++;
        }

    }

    public static int gcd(int x, int y) {
        for (int i=x; i>0; i--) {
            if(x%i == 0 && y%i == 0) {
                return i;
            }
        }

        return 1;
    }

}


import java.io.*;

public class start {

    public int max (int a, int b) {
        if (a>b) return a;
        else return b;
    }

    public int min (int a, int b) {
        if (a<b) return a;
        else return b;
    }

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

    long n, m, k;

    public void work() {
        try {
            //BufferedReader in = new BufferedReader(new FileReader("C:\\example\\a.txt"));
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "Cp1252"));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, "Cp1252"), true);
            String []words=in.readLine().split(" ");
            n=Integer.parseInt(words[0]);
            m=Integer.parseInt(words[1]);
            k=Integer.parseInt(words[2]);
            if (m<n) {
                long a=m; m=n; n=a;
            }
            long answer=0;
            if (k>m+n-2) answer=-1;
            else {
                if (m>k)
                    answer=m/(k+1)*n;
                else
                    answer=n/(k+2-m);
            }
            out.println(answer);
            in.close();
            out.close();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner obj=new Scanner(System.in);
        int arr[]=new int[10];

        for(int i=1;i<=6;i++)
        {
        int l=obj.nextInt();
         arr[l]++;
        }

        Arrays.sort(arr);
        if(arr[9]>=4)
        {
            if(arr[9]==4)
            {
            if(arr[8]==2){System.out.println("Elephant");break;}
            else { System.out.println("Bear");break; }
            }

            else if(arr[9]==6){System.out.println("Elephant");break;}

            else if(arr[9]==5){ System.out.println("Bear");break;}
        }
        else if(arr[9]<4)
        { System.out.println("Alien");break; }

    }
}


   // package com.company;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.lang.reflect.Array;
    import java.util.*;
    public class Main {

        public static void main(String[] args) throws IOException {
           Scanner s = new Scanner(System.in);
           //BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
             StringBuilder sb = new StringBuilder();//int n=Integer.parseInt(s.readLine());
              int n=s.nextInt();
              int[] a=new int[n];int ne=n/2;int no=n-ne;
              for(int i=0;i<n;i++){
                  a[i]=s.nextInt();
                  if(a[i]%2==0&&a[i]!=0) ne--;
                  else if(a[i]!=0) no--;
              }
              int[] e=new int[n];
              int ei=0;int[] o=new int[n];int oi=0;
              int[] mixed=new int[n];int flag=0;int j=0;
              int mi=0;int[] spe=new int[2];int spei=0;int[] spo=new int[2];int spoi=0;int ans=0;
              Arrays.fill(o,Integer.MAX_VALUE);   Arrays.fill(spo,Integer.MAX_VALUE);   Arrays.fill(spe,Integer.MAX_VALUE);
              Arrays.fill(e,Integer.MAX_VALUE);
              for(int i=0;i<n;i++){
                  if(a[i]==0&&flag==0){
                      flag=1;j=i-1;
                  }else if(a[i]==0&&flag==1){
                      continue;
                  }else if(flag==1){
                      flag=0;
                      if(j==-1){
                          if(a[i]%2==0){
                              spe[spei++]=i;
                          }else spo[spoi++]=i;
                          continue;
                      }
                      if(a[i]%2==0&&a[j]%2==0){
                          e[ei++]=i-j-1;
                      }else if((a[i]%2!=0&&a[j]%2!=0))
                          o[oi++]=i-j-1;
                      else ans+=1;
                  }else{
                 //     System.out.println(i);
                      if(i>0&&((a[i]%2==0&&a[i-1]%2!=0)||(a[i]%2!=0&&a[i-1]%2==0)))
                          ans+=1;
                  }
              }
      //      System.out.println(no);
        //    System.out.println(spo[0]);
            if(flag==1){
                flag=0;
                {
                    if(a[j]%2==0){
                        spe[spei++]=n-j-1;
                    }else spo[spoi++]=n-j-1;
                }}
     //       System.out.println(spo[0]);
                Arrays.sort(spe);
                  Arrays.sort(spo);
                  Arrays.sort(e);Arrays.sort(o);
         //   System.out.println(o[0]);

            if(spei>0&&(spe[0]<=e[0]||e[0]==0)){
                      if(spe[0]<=ne){
                          ne-=spe[0];
                      }else ans+=1;
                  }if(spei>1&&(spe[1]<=e[0]||e[0]==0)){
                      if(spe[1]<=ne){
                          ne-=spe[1];
                      }else ans+=1;
                }
          //  System.out.println(no+" "+spo[0]);
            if(spoi>0&&(spo[0]<=o[0]||o[0]==0)){
                    if(spo[0]<=no){
                 //       System.out.println("HI");
                        no-=spo[0];
                    }else ans+=1;
                }if(spoi>1&&(spo[1]<=o[0]||o[0]==0)){
                    if(spo[1]<=no){
                        no-=spo[1];
                    }else ans+=1;
                }
     //       System.out.println(spei);
               for(int i=0;i<ei;i++){
                      if(e[i]<=ne){
                          ne-=e[i];
                      }else ans+=2;
               }for(int i=0;i<oi;i++){
                if(o[i]<=no){
                    no-=o[i];
                }else ans+=2;
            }
            System.out.println(ans);
        }
        static boolean isPrime(int n)
        {
            // Corner cas
            if (n <= 1) return false;
            if (n <= 3) return true;

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

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

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

            // Try k times
            while (k > 0)
            {
                // Pick a random number in [2..n-2]
                // Above corner cases make sure that n > 4
                int a = 2 + (int)(Math.random() % (n - 4));

                // Fermat's little theorem
                if (power(a, n - 1, n) != 1)
                    return false;

                k--;
            }

            return true;
        }
        static double power(double x, long y, int p) {
            double res = 1;
            x = x % p;
            while (y > 0) {
                if ((y & 1) == 1)
                    res = (res * x) % p;
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }
        public static void fracion(double x) {
            String a = "" + x;
            String spilts[] = a.split("\\."); // split using decimal
            int b = spilts[1].length(); // find the decimal length
            int denominator = (int) Math.pow(10, b); // calculate the denominator
            int numerator = (int) (x * denominator); // calculate the nerumrator Ex
            // 1.2*10 = 12
            int gcd = gcd(numerator, denominator); // Find the greatest common
            // divisor bw them
            String fraction = "" + numerator / gcd + "/" + denominator / gcd;
            // System.out.println((denominator/gcd));
            long x1=modInverse(denominator / gcd,998244353  );
            //  System.out.println(x1);
            System.out.println((((numerator / gcd )%998244353 *(x1%998244353  ))%998244353  ) );
        }static int max=Integer.MIN_VALUE;
static int max1=Integer.MIN_VALUE;static int[] ans;static long[][] dp;static int[][] c;
        public static int dfs(int papa, int i, ArrayList<Integer>[] h, int[] vis) {

             vis[i] = 1;
               if(papa!=-1){
                   dp[i-1][0]=Math.min(dp[i-1][0],c[0][i-1]+Math.min(dp[papa-1][1],dp[papa-1][2]));
                   dp[i-1][1]=Math.min(dp[i-1][1],c[1][i-1]+Math.min(dp[papa-1][0],dp[papa-1][2]));
                   dp[i-1][2]=Math.min(dp[i-1][2],c[2][i-1]+Math.min(dp[papa-1][1],dp[papa-1][0]));

               }else{
                   dp[i-1][0]=c[i-1][0];
                   dp[i-1][1]=c[i-1][1];
                   dp[i-1][2]=c[i-1][2];

               }
             for(Integer j:h[i]){
                      if(vis[j]==0){
                          dfs(i,j,h,vis);
                      }
             }ans[i]+=1;if(ans[i]>max){
                 max=ans[i];max1=i;
            }
          return ans[i];
        }

        public static void bfs(int i, HashMap<Integer, Integer>[] h, int[] vis, int len, int papa) {
            Queue<Integer> q = new LinkedList<Integer>();
            q.add(i);

        }

        static int i(String a) {
            return Integer.parseInt(a);
        }

        static long l(String a) {
            return Long.parseLong(a);
        }

        static String[] inp() throws IOException {
            BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
            return s.readLine().trim().split("\\s+");
        }

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

            {
                // If a and m are relatively prime, then modulo inverse
                // is a^(m-2) mode m
                return (power(a, m - 2, m));
            }
        }

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

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

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

        // Function to return gcd of a and b

    }
    class Student
    {
        Integer l;Integer r;

        public Student(Integer l, Integer r) {
            this.l = l;
            this.r = r;

        }
    // Constructor

        // Used to print student details in main()
        public String toString()
        {
            return this.l+" ";
        }
    }

    class Sortbyroll implements Comparator<Student>
    {
        // Used for sorting in ascending order of
        // roll number
        public int compare(Student a, Student b){
            return b.r-a.r;
        }
    }


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

public class abc
{
public static void main(String[] args)
{
 Scanner sc = new Scanner(System.in);
 int n =sc.nextInt();
 int dp[] = new int[n];
 dp[0]=1;
 int i =0;
 if(n==1)
{
    System.out.println("1");
    return;
}
 for(i =1;i<n;i++)
 {
    dp[i]= dp[i-1]+(int)Math.pow(2,i+1);
 }
 System.out.println(dp[i]);
}}


import javax.print.attribute.IntegerSyntax;
import java.io.*;
import java.util.*;

/**
 * A simple template for competitive programming problems.
 */
public class Banana {
    final InputReader in = new InputReader(System.in);
    final PrintWriter out = new PrintWriter(System.out);

    final long mod = 998244353;

    final boolean DEBUG = false;
    void solve() {

        int n = in.nextInt();
        List<Map<Integer, Long>> dp = new ArrayList<>(n);

        dp.add(new HashMap<>());
        Map<Integer, Long> firstMap = new HashMap<>();
        firstMap.put(1, 1L);
        dp.add(firstMap);

        for(int i=2; i<=n; i++) {
            Map<Integer, Long> map = new HashMap<>();
            dp.add(map);
            int maxDiff = findMaxDiff(i);
            int minVal = (i-maxDiff-1)/2;
            for(int j=minVal; j<=minVal+maxDiff; j++) {
                long val = 0;
                Map<Integer, Long> leftMap = dp.get(j);
                Map<Integer, Long> rightMap = dp.get(i-1-j);
                if(leftMap.isEmpty()) {
                    for(Integer right : rightMap.keySet()) {
                        if(right%2!=0) continue;
                        long mul = rightMap.get(right) % mod;
                        val = (val+mul) % mod;
                    }
                } else if(rightMap.isEmpty()) {
                    for(Integer left : leftMap.keySet()) {
                        if(left%2==(j+1)%2) continue;
                        long mul = leftMap.get(left) % mod;
                        val = (val+mul) % mod;
                    }
                } else {
                    for(Integer left : leftMap.keySet()) {
                        if(left%2==(j+1)%2) continue;
                        for(Integer right : rightMap.keySet()) {
                            if(right%2!=0) continue;
                            long mul = leftMap.get(left)*rightMap.get(right) % mod;
                            val = (val+mul) % mod;
                        }
                    }
                }
                map.put(j+1, val);
            }
        }

        out.println(sumVal(dp.get(n)));
    }

    private long sumVal(Map<Integer, Long> map) {
        long val = 0;
        for(long mapVal : map.values()) {
            val = (val + mapVal) % mod;
        }
        return val;
    }

    private int findMaxDiff(int i) {
        int log = 31 - Integer.numberOfLeadingZeros(i);
        int deepestNodesCount = i - (1<<log) + 1;
        int deepestEmptyNodesCount = (1<<log) - deepestNodesCount;
        return Math.min(deepestEmptyNodesCount, deepestNodesCount);
    }

    public static void main(String[] args) throws FileNotFoundException { Banana s = new Banana(); s.solve(); s.out.close(); }

    public Banana() throws FileNotFoundException { }

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

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

        InputReader(String fileName) {
            InputStream stream = null;
            try {
                stream = new FileInputStream(fileName);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            this.stream = stream;
        }

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

        int[][] nextMatrix(int n, int m) {
            int[][] matrix = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    matrix[i][j] = nextInt();
            return matrix;
        }

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

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

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

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

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

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

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

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

}


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

public class e {
	static final long MOD = 998244353;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();
		long[][] sol = new long[2][N+1];
		sol[0][1] = 0;
		sol[1][1] = 1;
		sol[0][2] = 1;
		sol[1][2] = 0;

		for(int i=3;i<=N;i++) {

			int root = (i+1) / 2;
			int left = root - 1;
			int right = i-root;
			int parity = root%2!=right%2 ? 1 : 0;
			if(root%2 == (parity^1) && right==1)sol[root%2][i] = 0;
			else
				sol[root%2][i] = (sol[(root%2) ^ 1][left] * sol[parity^(root%2)][right]);

			if(i%2 == 1)continue;

			root = root+1;
			left = root-1;
			right = i-root;
			parity = root%2!=right%2 ? 1 : 0;
			if(root%2 == (parity^1) && right==1)sol[root%2][i] = 0;
			else
				sol[root%2][i] = (sol[(root%2) ^ 1][left] * sol[parity^(root%2)][right]);
		}

		System.out.println((sol[0][N]+sol[1][N])%MOD);
	}

	private static class FS {
		BufferedReader br;
		StringTokenizer st;

		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.TreeSet;

public class E {

    long N;
    TreeSet<Long> set;

    private class Data {
        int count;
        long num;

        public Data(long num, int count) {
            this.num = num;
            this.count = count;
        }
    }

    private char[] toChars(long n) {
        return String.valueOf(n).toCharArray();
    }

    private long toLong(char[] ch) {
        long ret = 0L;
        for(char c : ch) {
            ret *= 10;
            ret += c - '0';
        }
        return ret;
    }

    private void swap(int i,int j,char[] ch) {
        char tmp = ch[i];
        ch[i] = ch[j];
        ch[j] = tmp;
    }

    private void solve() {

        N = nextLong();

        set = new TreeSet<>();

        ArrayDeque<Data> q = new ArrayDeque<>();
        q.add(new Data(N, 0));

        while(q.size() > 0) {

            Data data = q.poll();

            if (data.num % 25 == 0) {
                out.println(data.count);
                return;
            }

            char[] ch = toChars(data.num);

            for(int i = 0;i < ch.length-1;i++) {
                swap(i,i+1,ch);
                if (i == 0 && ch[i] == '0') {
                    swap(i,i+1,ch);
                    continue;
                }
                long nextN = toLong(ch);
                if (!set.contains(nextN)) {
                     set.add(nextN);
                    q.add(new Data(nextN, data.count + 1));
                }
                swap(i,i+1,ch);
            }
        }
        out.println(-1);
    }

    public static void main(String[] args) {
        out.flush();
        new E().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


package test;

import java.util.Scanner;

public class Test {

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

		s = sc.nextLine();

		String[] tab = s.split(" ");

		int n=0, a=0, b=0, c=0;
		try {
			n = Integer.parseInt(tab[0]);
			a = Integer.parseInt(tab[1]);
			b = Integer.parseInt(tab[2]);
			c = Integer.parseInt(tab[3]);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		n=n%4;
		if(0<n)n=4-n;

		switch (n)
		{
		case 0:System.out.println(0);break;
		case 1: System.out.println(a);break;
		case 2:  if(2*a<b) System.out.println(2*a); else System.out.println(b);break;
		case 3: n=b+a; if(n<c && n<3*a )System.out.println(n); else if(3*a <c) System.out.println(3*a) ;else System.out.println(c);
		}
	}

}


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

public class B21 {

	static StreamTokenizer in;
	static PrintWriter out;

	static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}

	static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

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

		int a1 = nextInt(), b1 = nextInt(), c1 = nextInt();
		int a2 = nextInt(), b2 = nextInt(), c2 = nextInt();

		if (a1 < 0) {
			a1 *= -1;
			b1 *= -1;
			c1 *= -1;
		}
		else if (a1 == 0 && b1 < 0) {
			b1 *= -1;
			c1 *= -1;
		}

		if (a2 < 0) {
			a2 *= -1;
			b2 *= -1;
			c2 *= -1;
		}
		else if (a2 == 0 && b2 < 0) {
			b2 *= -1;
			c2 *= -1;
		}

		int g1 = gcd(a1, gcd(b1, c1));
		int g2 = gcd(a2, gcd(b2, c2));

		a1 /= g1; b1 /= g1; c1 /= g1;
		a2 /= g2; b2 /= g2; c2 /= g2;

		if (a1 == 0 && b1 == 0 && c1 != 0) out.println("0");
		else if (a2 == 0 && b2 == 0 && c2 != 0) out.println("0");
		else if (a1 == 0 && b1 == 0 && c1 == 0) out.println("-1");
		else if (a2 == 0 && b2 == 0 && c2 == 0) out.println("-1");
		else if (a1 == a2 && b1 == b2 && c1 == c2) out.println("-1");
		else if (a1*b2 - b1*a2 == 0) out.println("0");
		else out.println("1");

		out.flush();
	}

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


//package codeforces.GoodBye17;

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

public class D
{
	static int mod = (int)1e9+7;
	static Pair[][] memo;
	static int a,b,k, a_b;
	static Pair sum1, pb, pa, sum2;
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		k = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		a_b = sum(a, b);
		memo = new Pair[a+2][k+2];

		Pair one = new Pair(1, 1);
		pa = new Pair(a, a_b);
		pb = new Pair(b, a_b);
		sum1 = new Pair(one, one.subtract(pa));

		Pair one_pa = one.subtract(pa);
		Pair pp1 = new Pair(pa, one_pa);
		Pair pp2 = new Pair(one, one_pa);
		sum2 = pp1.multiply(pp2);

		Pair p = simplify(solve(1, 0));
		int rp = p.x;
		int rq = p.y;
		System.out.println(mult(rp, inv(rq, mod)));

		pw.flush();
		pw.close();
	}

	private static Pair simplify(Pair P)
	{
		int gcd = gcd(P.x, P.y);
		P.x = mult(P.x, inv(gcd, mod));
		P.y = mult(P.y, inv(gcd, mod));
		return P;
	}

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

	static int sub(int a, int b)
	{
		int ans = a-b;
		ans %= mod;
		if(ans < 0)
			ans += mod;
		return ans;
	}

	private static Pair solve(int cntA, int tot)
	{
		if(tot >= k)
			return new Pair(tot, 1);
		if(cntA+tot >= k) // check > or >=
		{
			return pb.multiply(new Pair(tot+cntA, 1).multiply(sum1).add(sum2));
		}

		if(memo[cntA][tot] != null)
			return memo[cntA][tot];

		// a
		int num1 = mult(a, solve(cntA+1, tot).x);
		int den1 = mult(a_b, solve(cntA+1, tot).y);
		Pair a1 = new Pair(num1, den1);
		// b
		int num2 = mult(b, solve(cntA, tot+cntA).x);
		int den2 = mult(a_b, solve(cntA, tot+cntA).y);
		Pair a2 = new Pair(num2, den2);

		return memo[cntA][tot] = a1.add(a2);
	}

	static int mult(int a, int b)
	{
		return (int)(1l*a*b % mod);
	}

	static int sum(int a, int b)
	{
		return (a+b) % mod;
	}

	static class Pair
	{
		int x, y;

		public String toString()
		{
			return x +"/" + y;
		}
		public Pair(int x, int y)
		{
			this.x = x;
			this.y = y;
		}

		public Pair(Pair p1, Pair p2)
		{
			this.x = mult(p1.x, inv(p2.x, mod));
			this.y = mult(p1.y, inv(p2.y, mod));
		}

		Pair multiply(Pair p)
		{
			return new Pair(mult(x, p.x),  mult(y, p.y));
		}

		Pair add(Pair p)
		{
			int xy = mult(p.y, y);
			return new Pair(sum(mult(mult(xy, x), inv(y, mod)), mult(mult(p.x, xy), inv(p.y, mod))),  mult(y, p.y));
		}

		Pair subtract(Pair p)
		{
			Pair tmp = new Pair(-p.x, p.y);
			tmp.x %= mod;
			if(tmp.x < 0)
				tmp.x += mod;
			return add(tmp);
		}
	}

	static int inv(long  x , long mod){
		long r, y;
		for(r = 1 , y = mod - 2 ; y != 0 ;x = x * x % mod, y>>=1)
		if ((y & 1) == 1)
		r = r * x % mod;
		return (int)r;
		}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String s) throws FileNotFoundException
		{
			br = new BufferedReader(new FileReader(new File((s))));
		}

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

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

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

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

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

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