import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int n=3;
 int[][] co=new int[n][];
 for(int i=0;i<n;i++) co[i]=ir.nextIntArray(2);
 if((co[0][0]==co[1][0]&&co[1][0]==co[2][0])||(co[0][1]==co[1][1]&&co[1][1]==co[2][1])){
  out.println(1);
  return;
 }
 for(int k=0;k<2;k++){
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
    if(co[i][k]==co[j][k]){
     if((long)(co[i][k^1]-co[d(i,j)][k^1])*(co[d(i,j)][k^1]*co[j][k^1])<0){
      out.println(3);
     }
     else out.pritln(2);
     return;
    }
   }
  }
 }
 out.println(3);
}

public static int d(int a,int b){
 if(a==0&&b==1) return 2;
 if(a==0&&b==2) return 1;
 return 0;
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

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

 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}

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

 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

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

 public BigInteger nextBigInteger(){return new BigInteger(next());}

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

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

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


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

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

		InputStream is=System.in;
		OutputStream output=System.out;
		FastScannerr scan=new FastScannerr(is);
		FastPrinterr out=new FastPrinterr(output);
		long b=scan.nextLong();
		long[] arr=new long[(int)b+1];
		Arrays.fill(arr, 1);
		for(int i=2;i<b;i++)
		 {
			for(int j=i*i;j<b;j+=i)
			{
				arr[j]=0;
			}
		 }
		arr[0]=0;
		long ans=1;
		if(b>1)
		{
			ans=2;
		}
		for(int i=2;i<b;i++)
		{
			if(arr[i]==1&&b%i==0)
			{
				long temp=i;
				while(temp<b)
				{
				  ans++;
				  temp*=i;
				}
			}
		}
		out.println(ans);
		out.flush();
	}

}
class FastPrinterr extends PrintWriter
{
	public FastPrinterr(OutputStream out)
	{
		super(out);
	}
}
class FastScannerr
{
	BufferedReader br;
	StringTokenizer st;
	public FastScannerr(InputStream is)
	{
		br=new BufferedReader(new InputStreamReader(is));
	}

	public String next()
	{
	  while(st==null||!st.hasMoreElements())
	  {
		  String s=null;
		  try
		    {
			  s=br.readLine();
		    }
		  catch(IOException io)
		    {
			  io.printStackTrace();
		    }

		  if(s==null)
		  {
			  return null;
		  }
		  st=new StringTokenizer(s);
	  }
	  return st.nextToken();
	}
	public long nextLong()
	{
		return Long.parseLong(next());
	}
	public int nextInt()
	{
		return Integer.parseInt(next());
	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static boolean fileIO = true;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static long iinf = (long)1e18 + 5l;
    public static void solve()throws IOException {
        long ties = f.nl(); long scarf = f.nl(); long vest = f.nl(); long jacket = f.nl();
        long first = f.nl(); long sec = f.nl();
        long max = -iinf;
        for(long i = 0; i <= jacket; ++i) {
            long cost1 = Math.min(ties , i) * first;
            long cost2 = Math.min(Math.min(vest , scarf) , jacket - i) * sec;
            max = Math.max(max , cost1 + cost2);
        }
        pn(max);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(fileIO){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{String fl=null;while(st==null||!st.hasMoreTokens()){try{fl=br.readLine();}catch(IOException e){throw new RuntimeException(e);}return fl;}return fl;}
        int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long 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){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1l)==0l);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


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

public class Solution {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        System.out.println(26 * (line.length() + 1) - line.length());
}


import java.util.Scanner;
/**
 *
 * @author ASUS
 */
public class Revresing {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        String r=in.next();
        char chars[]=r.toCharArray();
        for (int i=a;i>1;i--)
        {
            if(a%i==0)
            {
                for(int j=i;j>1;j--)
                System.out.print(r[j]);
            }
        }

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

    static class CIvanTheFoolAndTheProbabilityTheory {
        long mod = (long) (1e9 + 7);
        int n;
        int m;
        int[][] mat;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            n = in.scanInt();
            m = in.scanInt();
            if (n == 1 && m == 1) {
                out.println(2);
                return;
            }

            mat = new int[n][m];

            if (n > m) {
                int temp = n;
                n = m;
                m = temp;
            }

            long dp[][] = new long[3][2];
            dp[1][0] = 1;
            dp[1][1] = 1;
            dp[2][0] = 2;
            dp[2][1] = 2;

            long f[] = new long[(int) (m + 5)];
            f[1] = 2;
            f[2] = 4;
            for (int i = 3; i <= m; i++) {

                int cu = i % 3;
                int pre = (i - 1) % 3;
                int sec_pre = (i - 2) % 3;
                dp[cu][0] = dp[cu][1] = 0;
                {
                    dp[cu][0] = sum(dp[cu][0], dp[pre][1]);
                    dp[cu][0] = sum(dp[cu][0], dp[sec_pre][1]);

                }
                {
                    dp[cu][1] = sum(dp[cu][1], dp[pre][0]);
                    dp[cu][1] = sum(dp[cu][1], dp[sec_pre][0]);
                }
                f[i] = sum(dp[cu][0], dp[cu][1]);

            }

            if (n == 1 || m == 1) {
                out.println(f[Math.max(n, m)]);
                return;
            }

            long ans = sum(f[n], f[m] - 2);
            out.println(ans);

        }

        long sum(long a, long b) {
            while (a < 0) a += mod;
            while (b < 0) b += mod;
            return (a + b) % mod;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

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

    }
}


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

public class main {

	static final long K=998244353;

	static long mu(long a, long n) {
		if (n==0) return 1;
		long q=mu(a,n/2);
		if (n%2==0) return q*q%K;
		return q*q%K*a%K;
	}

	static long [] gt= new long[1000005];
	static long [] rev= new long[1000005];
	static long n;

	static long Combi(long n, long k){
		if (k>n) return 0;
		return gt[(int) n]*rev[(int) k]%K*rev[(int) (n-k) ]%K;
	}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
		gt[0]=rev[0]=1;
		for (int i=1; i<=1000000; i++){
			gt[i]=gt[i-1]*1l*i%K;
			rev[i]=mu(gt[i],K-2);
		}

		n=in.nextLong();
		long A=mu(3,n*n);
		long q=(mu(3,n)+K-3) %K;
		q=mu(q,n);
		A=(A-q+K)%K;

		long C=0; long t=1;
		if (n%2==0) t=-1;
		for (long x=0 ; x<n; x++) {
			long z=(mu(3,n*x)*t+K)%K;
			long w=(mu(3,x)+K-1)%K;
			w=mu(w,n)*(-t);
			w=(w+K)%K;
			z=(z+w)%K;
			long Y=Combi(n,x)*z%K;
			if (x%2==1){
				C=(C+Y)%K;
				//cout<<x<<" "<<Y<<endl;
			}
			else {C=(C-Y+K)%K;} //cout<<x<<" "<<(K-Y)%K<<endl;}
		}
		long res=(2*A+3*C)%K;
		res=(res+K)%K;
		out.println(res);

        out.close();
    }

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

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }
		public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.Scanner;
public class B {
public static void main (String []args ){
Scanner in =new Scanner (System.in);
int b= in.nextInt();
boolean s=true;
for(int i=0 ;i<10 ; i++)
{
  if(Math.Pow(2,i)==b){
System.out.Println("YES");break;s=false;}
}
if(s)
System.out.Println("NO");

}
}


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

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

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long t1 = in.nextLong();
        long t2 = in.nextLong();
        long X1 = in.nextLong();
        long X2 = in.nextLong();
        long t0 = in.nextLong();
        BigDecimal T0 = BigDecimal.valueOf(t0);

        BigDecimal cur = null;
        long optXA = 0, optXB = 0;

        for (long xa = X1; xa >= 0; --xa) {
            long xb = getXB(t1, t2, t0, xa) - 5;

            for (int delta = -5; delta <= 5; ++delta, ++xb) {
                if (xa + xb <= 0) continue;
                if (xb <= X2 && xb >= 0) {
                    BigDecimal T = getSpeed(t1, t2, xa, xb);
                    if (T.compareTo(T0) >= 0) {
                        if (cur == null || cur.compareTo(T) > 0 || cur.compareTo(T) == 0 && optXA + optXB < xa + xb) {
                            cur = T;
                            optXA = xa;
                            optXB = xb;
                        }
                    }
                }
            }
        }
        out.println(optXA + " " + optXB);
    }

    private BigDecimal getSpeed(long t1, long t2, long xa, long xb) {
        double up = t1 * xa + t2 * xb;
        double down = xa + xb;
        return new BigDecimal(up / down);
    }

    private long getXB(long t1, long t2, long t0, long xa) {
        long up = (t0 - t1) * xa;
        long down = (t2 - t0);
        return up / down;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

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

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

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

}


import java.util.Scanner;
import java.io.*;
public class main {
    public static void main(String args[])throws Exception{
        Scanner in = new Scanner (System.in);

        String s1 =in.next().toLowerCase();
        String s2=in.next().toLowerCase();
        if(s1==s2)
                System.out.println(0);

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

            if(s1.charAt(i)>s2.charAt(i)){
                System.out.println(1);break;
            }
            else if(s1.charAt(i)<s2.charAt(i)){
                System.out.println(-1);break;
            }
        }
    }
}


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

public class PetyaAndStrings {

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

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

		String str1=br.readLine();
		String str2=br.readLine();
		boolean isEqual=true;
		for(int i=0;i<str1.length();i++){
			Character c1=Character.toLowerCase(str1.charAt(str1.length()-1));
			Character c2=Character.toLowerCase(str2.charAt(str1.length()-1));
			if(!c1.equals(c2)){

				isEqual=false;
				if(c1>c2){
					System.out.println(1);
					break;
				}else if(c2>c1){
					System.out.println(-1);
					break;
				}
			}
		}
		if(isEqual){
		System.out.println(0);
		}

	}

}


public class Cossack {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int n,m,k;
        Scanner input=new Scanner(System.in);
        n=input.nextInt();
        m=input.nextInt();
        k=input.nextInt();
        while (1 <= n && n <=100 && 1 <=m && m <= 100 && 1 <=k && k<=100 ){
            if (m<n || k<n )
            {
                System.out.println("no");
            }
            else
            {
                System.out.println("yes");
        }
        }
    }
}


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

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

    static class AMiddleOfTheContest {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String h1 = in.next();
            String h2 = in.next();
            double h1val = Double.parseDouble(h1.substring(0, 2));
            int m1val = Integer.parseInt(h1.substring(3, 5));
            double h2val = Double.parseDouble(h2.substring(0, 2));
            int m2val = Integer.parseInt(h2.substring(3, 5));
            double h3 = (h1val + h2val) / 2;
            int m3 = (m1val + m2val) / 2;
            if (h3 == (int) h3)
                h3 = h3;
            else {
                h3 = (int) h3;
                m3 += 30;
            }
            if (m3 > 59) {
                h3 = h3 + m3 / 60;
                m3 = m3 % 60;
            }

            if (h3 < 5 && m3 < 5)
                out.println("0" + (int) h3 + ":" + "0" + m3);
            else if (m3 < 5)
                out.println((int) h3 + ":" + "0" + m3);
            else if (h3 < 5)
                out.println("0" + (int) h3 + ":" + m3);
            else
                out.println((int) h3 + ":" + m3);
        }

    }
}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> dividers = getDividers((int)1e5);
        Collections.reverse(dividers);

        int n = sc.nextInt();
        for (int div : dividers) {
            if (n % div == 0) {
                System.out.println(div);
                return;
            }
        }
    }

    public static List<Integer> getDividers(int limit) {
        int n1 = 1;
        int n2 = 1;
        int mul = 2;

        List<Integer> dividers = new ArrayList<>();
        for (int div; (div = n1 * n2) <= limit; n1 = mul, mul *= 2, n2 = mul - 1) {
            dividers.add(div);
        }
        return dividers;
    }
}


import java.util.*;
public class stone
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int m,count=0;
        String s;
        m=sc.nextInt();
        s=sc.next();
        for(int i=0;i<m;i++)
        {
            if(s.charAt(i)=='-') count--;
            if(count<0) count=0;
            if(s.charAt(i)=='+') count++;
        }
        system.out.println(count);
        sc.close();
    }
}


import java.util.Scanner;

public class snowball_1099A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int w = s.nextInt();
        int h = s.nextInt();
        int u1 = s.nextInt();
        int d1 = s.nextInt();
        int u2 = s.nextInt();
        int d2 = s.nextInt();

        int w1;
        int h1;
        int w2;
        int h2;

        if(d1 > d2){
            h1 = d1;
            w1 = u1;
            h2 = d2;
            w2 = u2;
        }
        else{
            h1 = d2;
            w1 = u2;
            h2 = d1;
            w2 = u1;
        }

        while(h >= h1){
            w = w+h;
            h--;
        }
        w = Math.max(0, w-w1);
        while(h >= h2){
            w = w+h;
            h--;
        }
        w = Math.max(0, w-w2);
        while(h>0){
            w =w+h;
        }
        System.out.println(w);
    }
}


import java.util.*;
public class problem1 {
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		ArrayList a = new ArrayList ();
		while (sc.hasNextInt()) {
			a.add(sc.nextInt());
		}
		int max = findMaxIndex (a);
		int min = findMinIndex (a);
		int add = min < (n-1-max) ? (n-1-max) : min;
		int dis = max < min ? (min - max) : (max -min);
	    System.out.println(add + dis);

	}

	public static int findMaxIndex (ArrayList a) {
		int i = 0;
		int v = (int) a.get(0);
		int n = a.size();
		int j = 1;
		while ( j <= n-1 ) {
			int t = (int) a.get(j);
			if (v < t) {
				i = j;
				v = t;
			}
		}
		return i;
	}
	public static int findMinIndex (ArrayList a) {
		int i = 0;
		int v = (int) a.get(0);
		int n = a.size();
		int j = 1;
		while ( j <= n-1 ) {
			int t = (int) a.get(j);
			if (t < v) {
				i = j;
				v = t;
			}
		}
		return i;
	}
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int indexMin = 0;
        int indexMax = 0;
        for(int i = 0; i < n; i++) {
            int num = scan.nextInt();
            if(num == 1) {
                indexMin = i;
            }
            if(num == n) {
                indexMax = i;
            }
        }
        int max = Math.max(indexMin, indexMax);
        int min = Math.min(indexMin, indexMax);
        int res;
        if(min < n-max) {
            res = n - min-1;
        } else {
            res = max-1;
        }
        System.out.println(res);
    }
}


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

public class P1 {

    class Point{
        int x1,y1,x2,y2;
        Point(int X1, int Y1, int X2, int Y2) {
            x1 = X1;
            y1 = Y1;
            x2 = X2;
            y2 = Y2;
        }
    }

    public static void main(String[] args) {
        P1 p1 = new P1();
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n = scan.nextInt();
        Point[] points = new Point[n];
        int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = 0, maxY=0;
        for (int i=0; i<n; i++){
            int x1 =  scan.nextInt();
            int y1 =  scan.nextInt();
            int x2 =  scan.nextInt();
            int y2 =  scan.nextInt();

            if (x1<minX) minX = x1;
            if (y1<minY) minY = y1;
            if (x2>maxX) maxX = x2;
            if (y2>maxY) maxY = y2;

            points[i] = p1.new Point(x1,y1,x2,y2);
        }
        scan.close();
        int deltaX = maxX-minX;
        int deltaY = maxY-minY;
        if ((deltaX)!=(deltaY)){
            System.out.println("NO");
        } else {
            boolean[][] matrix = new boolean[deltaX][deltaY];
            for (int i=0; i<deltaX; i++)
                Arrays.fill(matrix[i], false);

            for (int i=0; i<n; i++){
                for (int j=points[i].x1-minX; j<points[i].x2-minX; j++){
                    for (int k=points[i].y1-minY; k<points[i].y2-minY; k++){
                        matrix[j][k] =  true;
                    }
                }
            }
            boolean result = true;
            for (int j=0; j<deltaX; j++){
                for (int k=0; k<deltaY; k++){
                    result = result && matrix[j][k];
                }
            }

            if (result)
                System.out.println("YES");
            else
                System.out.println("NO");

        }
    }

}


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

 //@Manan Parmar

public class Solution2 implements Runnable {

    public void run() {

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

        long n=sc.nextLong(),m=sc.nextLong(),a=sc.nextLong(),b=sc.nextLong(),x=0,y=0;
        if(n%m==0)
            out.println("0");
        else
        {
            if(n>m)
            {
                long z=n,z1=m,p=n,p1=m;
                while(z%z1!=0)
                    z++;
                x=(z-n)*a;
                y=(p-p1)*b;
                out.println(Math.min(x,y));
            }
            else
            {
                long z=n,z1=m;
                while(z%n!=0)
                    z--;
                x=z*b;
                y=(m-n)*a;
                out.println(Math.min(x,y));
            }
        }
        out.close();
    }

//========================================================================

    static void insertionSort(int a[],int n)
    {
        for(int i=1;i<n;i++)
        {
            int min=i,j=i-1;
            while(j>=0)
            {
                if(a[j]>a[min])
                {
                    int temp=a[min];
                    a[min]=a[j];
                    a[j]=temp;
                }
                j--;
            }
            a[i]=a[min];
        }
    }
    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 Solution2(),"Main",1<<27).start();
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class C {
    public static int n;
    public static int k;
    public static int[][] dp = new int[n+1][k+1];
    public static int[] cum = new int[n+1];
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int n = Integer.parseInt(st.nextToken());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int[][] dp = new int[n+1][k+1];
        int[][] cum = new int[n+1][k+1];
        for(int i=0; i<n+1; i++) {
            dp[i][0] = 1;
            cum[i][0] = i+1;
        }

        for(int j=1; j<k+1; j++) {
            for(int i=1; i<n+1; i++) {
                if(i == b) continue;
                if(i < b)
                    dp[i][j] = (int)((1L*cum[b-1][j-1]-cum[(int)Math.min(Math.max(2*i-b, 0), n)][j-1]-dp[i][j-1] + 2*1000000007)%1000000007);
                else
                    dp[i][j] = (int)((1L*cum[(int)Math.min(Math.max(2*i-b-1, 0), n)][j-1]-cum[b][j-1]-dp[i][j-1] + 2*1000000007)%1000000007);
            }
            long counter = 0;
            for(int i=0; i<n+1; i++) {
                counter += dp[i][j];
                counter %= 1000000007;
                cum[i][j] = (int)(counter % 1000000007);
            }
        }
        // for(int i=0; i<dp.length; i++) System.out.println(Arrays.toString(dp[i]));
        System.out.println(dp[a][k]);
        // Scanner scan = new Scanner(System.in);
        // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());
        // int n = scan.nextInt();

        // out.close(); System.exit(0);
    }
}


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

public class Solver {

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

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

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

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

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

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

	final long del=(long)1e9+7;

	int n;
	int kolStep;
	int start;
	int finish;
	long[][] result;

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

		n=nextInt();
		start=nextInt()-1;
		finish=nextInt()-1;
		kolStep=nextInt();
		result=new long[kolStep+1][n];
		for (int i=0; i<n; i++){
			result[0][i]=1;
		}
		for (int i=1; i<=kolStep; i++){
			long[] partSum=new long[n+1];
			partSum[0]=0;
			for (int k=0; k<n; k++){
				partSum[k+1]=partSum[k]+result[i-1][k];
			}

			for (int j=0; j<n; j++){
				int dist=Math.abs(j-finish)-1;
				int begin=j-dist;
				int end=j+dist;
				if (begin<0)
					begin=0;
				if (end>=n)
					end=n-1;
				if (begin>end)
					result[i][j]=0;
				else {
					result[i][j]=(partSum[end+1]-partSum[begin]-result[i-1][j])%del;
				}
			}
		}
		pw.println(result[kolStep][start]);
		pw.flush();
		pw.close();
	}

}


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

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

        int m = Integer.parseInt(br.readLine());
        st = new StringTokenizer(br.readLine());
        int h1 = Integer.parseInt(st.nextToken()), a1 = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int x1 = Integer.parseInt(st.nextToken()), y1 = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int h2 = Integer.parseInt(st.nextToken()), a2 = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int x2 = Integer.parseInt(st.nextToken()), y2 = Integer.parseInt(st.nextToken());

        int start = h1, current = h1;
        boolean flag1 = false;
        ArrayList<Integer> frog = new ArrayList<Integer>();
        do {
            frog.add(current);
            current = (x1 * current + y1) % m;
            if (current == a1) {
                flag1 = true;
            }

        } while (current != start);

        start = h2; current = h2;
        boolean flag2 = false;
        ArrayList<Integer> flower = new ArrayList<Integer>();
        do {
            flower.add(current);
            current = (x2 * current + y2) % m;
            if (current == a2) {
                flag2 = true;
            }

        } while (current != start);

        int l1 = frog.size(), l2 = flower.size();
        if (l1 == 1 || l2 == 1 || !flag1 || !flag2) {
            System.out.println(-1);
            return;
        }

        int seconds = 0;
        for (int i = 0; i < l1; i++) {
            if (frog.get(i) == a1) {
                break;
            }
            seconds++;
        }

        int position = seconds % l2;
        current = flower.get(position);
        boolean[] visited = new boolean[m];
        while (!visited[current]) {
            if (current == a2) {
                System.out.println(seconds);
                return;
            }
            visited[current] = true;

            seconds += l1;
            position += l1;
            position %= l2;
            current = flower.get(position);
        }

        System.out.println(-1);
    }
}


import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.Scanner;

/**
 *
 * @author lab
 */
public class Main  {

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

      String s=in.next();

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

      if(s.length()==1)
      {
          if(x[0].equals("A")|| x[0].equals("E") || x[0].equals("I") || x[0].equals("O") || x[0].equals("U") || x[0].equals("Y"))
              System.out.println(1);

          System.exit(0);
      }
      int count=0;
      for(int i=0;i<x.length;i++)
      {
          int count2=0;
          for(int y=i+1;y<x.length;y++)
          {
              if(x[y].equals("A")|| x[y].equals("E") || x[y].equals("I") || x[y].equals("O") || x[y].equals("U") || x[y].equals("Y"))
              {
                  count2++;
                  break;
              }
              else
                  count2++;
          }

          if(count2>count)
              count=count2;
      }

        System.out.println(count);

    }


/**
 * @author: Mehul Raheja
 */

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

public class A{

    /*
        Runtime = O()
     */
    static int N, M, K;
    static String s;
    static StringTokenizer st;
    static int[] d;

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long ans = 0;
        int N = Integer.parseInt(br.readLine());
        for (int i = 0; i < N; i++) {
            ans += Math.abs(Integer.parseInt(br.readLine()));
        }
        System.out.println(ans);
    }
}


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

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

    static class TaskC {
        static final int INF = (int) 1e9;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int nk = 0;
            int nv = 0;
            int no = 0;
            int[] kpos = new int[n];
            int[] vpos = new int[n];
            int[] opos = new int[n];
            int[] snk = new int[n + 1];
            int[] snv = new int[n + 1];
            int[] sno = new int[n + 1];
            for (int i = 0; i < n; ++i) {
                char ch = s.charAt(i);
                if (ch == 'V') {
                    vpos[nv++] = i;
                } else if (ch == 'K') {
                    kpos[nk++] = i;
                } else {
                    opos[no++] = i;
                }
                snk[i + 1] = nk;
                snv[i + 1] = nv;
                sno[i + 1] = no;
            }
            int[][][][] best = new int[2][nk + 1][nv + 1][no + 1];
            for (int[][][] x : best) for (int[][] y : x) for (int[] z : y) Arrays.fill(z, INF);
            best[0][0][0][0] = 0;
            for (int k = 0; k <= nk; ++k) {
                for (int v = 0; v <= nv; ++v) {
                    for (int o = 0; o <= no; ++o) {
                        for (int hv = 0; hv < 2; ++hv) {
                            int cur = best[hv][k][v][o];
                            if (k < nk && hv == 0) {
                                best[0][k + 1][v][o] = Math.min(best[0][k + 1][v][o], cur + Math.max(snv[kpos[k]] - v,0) + Math.max(sno[kpos[k]] - o),0);
                            }
                            if (v < nv) {
                                best[1][k][v + 1][o] = Math.min(best[1][k][v + 1][o], cur + Math.max(snk[vpos[v]] - k,0) + Math.max(sno[vpos[v]] - o),0);
                            }
                            if (o < no) {
                                best[0][k][v][o + 1] = Math.min(best[0][k][v][o + 1], cur + Math.max(snv[opos[o]] - v,0) + Math.max(snk[opos[o]] - k),0);
                            }
                        }
                    }
                }
            }
            out.println(Math.min(best[0][nk][nv][no], best[1][nk][nv][no]) );
        }

    }

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

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

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

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

    }
}


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

public class Main {

	public static void main(String[] args) {
		Solution.FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int T = in.nextInt();
		long MOD = (long)(1e9+7);
		int n = in.nextInt();
		long ans = n;
		long sub = 1;
		for(int i=1;i<n;i++) {
			sub = sub*2;
			ans = ans*i;
			ans = ans%MOD;
			sub = sub%MOD;
		}
		ans = ans-sub;
		out.println(ans<0?(ans+MOD):ans);
		out.flush();
		out.close();
	}

	static final Random random=new Random();
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static void ruffleSort(char[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n);
			char temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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


import java.util.Scanner;
public class Test {
	public static void main(String[] args) {
		int x ;
		Scanner sc = new Scanner(System.in);
		x=sc.nextInt();
		if(x%3==0 || x%9==1)
		{
			System.out.println("YES");
		}else
		{
			System.out.println("NO");
		}
	}
}


import java.util.Scanner;
//~O(nQ)
public class BearAndCompressing {
	public static void main(String[] raggs)
	{
		char[][] replacementArr = new char[6][36];

		int[] count = new int[6];
		int[] temp = new int[6];

		//System.out.println("gfim");
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();

		for(int i =0 ; i < 6; i++)
		{
			for(int j = 0; j < 36; j++)
			{
				replacementArr[i][j] = '0';
			}
		}

		in.nextLine();

		for(int i = 0; i < q; i++)
		{
			String line;
			char twoletter,oneletter;

			line = in.nextLine();

			twoletter = line.charAt(0);
			oneletter = line.charAt(3);

			for(int j = 0; j < 36; j++)
			{
				if(replacementArr[(int)(oneletter-'a')][j] == '0')
				{
				   replacementArr[(int)(oneletter-'a')][j] = twoletter;
				   break;
				}
			}
		}

		//start with one 'a'
		count[0] = 1;

		for(int i = 0; i < n-1; i++)
		{
			//for every cell in the array:
			for(int j = 0; j < 6; j++)
			{
				int occurances = count[j];
				//System.out.println(j + " " + occurances);
				for(int k = 0; k < 36; k++)
				{
					//Replace j with {replacement[j][k] for every k}
					char replaceWith = replacementArr[j][k];
					if(replaceWith == '0') break;

					int rw = (int)(replaceWith-'a');
					temp[rw] += occurances;
				}
			}
			//Now push temp ->count, and delete temp
			for(int x = 0; x < 6; x++)
		    {
				count[x] = temp[x];
				temp[x] = 0;
		    }

		}

		int sum = 0;

		for(int i = 0; i < 6; i++) sum += count[i];
		System.out.println(sum);
		/*
		for(int i =0 ; i < 6; i++)
		{
			for(int j = 0; j < 36; j++)
			{
				System.out.print(replacementArr[i][j] + " ");
			}
			System.out.println();
		}*/
	}
}


import java.util.Scanner;

public class Football96A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String teamform = in.nextLine();
        if(teamform.length() < 7){
            System.out.println("NO");
            return;
        }
        char[] formChar = teamform.toCharArray();
        int count = 0;
        for(int i = 0; i < formChar.length; i++){
            if(formChar[i] == formChar[i+1]){
                count++;
            }
            if(count == 7){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");

    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
 *
 * @author fz
 */
public class CF_rnd274E {
    Scanner in = new Scanner(System.in);

    private CF_rnd274E() throws IOException {
        //in.nextLine();
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();
        //int L = 5000;
        int[][] dp = new int[n + 1][k + 1];
        int MOD = 1000000007;
        dp[a][0] = 1;
        int[][] sum = new int[n + 1][k + 1];
        for(int i = 1; i < sum.length; i++){
            sum[i][0] = sum[i - 1][0] + dp[i][0];
        }
        for(int j = 1; j < k + 1; j++){
            for(int i = 1; i < n + 1; i++){
                int left = -1;
                int right = -1;
                if(i == b)
                    continue;
                else if(i < b) {
                    left = 0;
                    if((i + b) % 2 == 0)
                        right = (i + b) / 2 - 1;
                    else
                        right = (i + b) / 2;
                }
                else if(i > b) {
                    if((i + b) % 2 == 0)
                        left = (i + b) / 2;
                    else
                        left = (i + b) / 2;
                    right = n;
                }
                dp[i][j] = sum[right][j - 1] - sum[left][j - 1] - dp[i][j - 1];
                while(dp[i][j] > MOD) {
                    dp[i][j] -= MOD;
                }
                while(dp[i][j] < 0){
                    dp[i][j] += MOD;
                }

                sum[i][j] = sum[i - 1][j] + dp[i][j];

                while(sum[i][j] > MOD) {
                    sum[i][j] -= MOD;
                }
                while(sum[i][j] < 0){
                    sum[i][j] += MOD;
                }
            }
        }
        //for(int i = 1; i < n + 1; i++)
        //    out(Arrays.toString(dp[i]));

        int res = 0;
        for(int i = 1; i < n + 1; i++)
            res = (res + dp[i][k]) % MOD;
        out(res);

    }

    private int[] ns(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }
    private int[][] nmat(int m, int n) {//m rows and n cols
        int[][] res = new int[m][n];
        for(int i = 0; i < m; i++)
            for(int j = 0; j < n; j++)
                res[i][j] = in.nextInt();
        return res;
    }

    private static void out(Object x) {
        System.out.println(x);
    }
    public static void main(String[] args) throws IOException {
        new CF_rnd274E();
    }
}


import java.io.*;
public class stones
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,c,n;
  c=0;
  char p;
  String s;
  n=Integer.parseInt(in.readLine());
  s=in.readLine();
  for(i=0;i<n;i++)
  {
   p=s.charAt(i);
   if(p=='-1')
   c--;
   else
   c++;
   if(c<0)
   c=0;
  }
  System.out.println(c);
 }
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class ProblemC {
	static final long MOD = 1000000007;

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

		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0 ; i < n ; i++) {
			a[i] = in.nextLong();
		}
		Arrays.sort(a);

		long best = Long.MAX_VALUE;

		boolean[] isp = new boolean[1000010];
		Arrays.fill(isp, true);
		isp[1] = false;
		for (int i = 2 ; i < 1000010 ; i++) {
			if (isp[i]) {
				for (long ii = 1L * i * i ; ii < 1000010 ; ii += i) {
					isp[(int)ii] = false;
				}
			}
		}
		List<Integer> primes = new ArrayList<Integer>();
		for (int i = 1 ; i < 1000010 ; i++) {
			if (isp[i]) {
				primes.add(i);
			}
		}

		cnt = new long[n];
		for (int i = 0 ; i < n ; i++) {
			long nw = a[i];
			for (int p : primes) {
				while (nw % p == 0) {
					nw /= p;
					cnt[i]++;
				}
			}
			if (nw >= 2) {
				cnt[i]++;
			}
		}
		N = n;

		int[] parent = new int[n];
		Arrays.fill(parent, -1);

		out.println(doit(0, a, parent));
		out.flush();
	}

	static int N;
	static long[] cnt;

	public static long doit(int done, long[] a, int[] parent) {
		if (done == (1<<N)-1) {
			long best = 0;
			for (int i = 0 ; i < N ; i++) {
				long deg = cnt[i];
				boolean hasChild = false;
				for (int j = 0 ; j < N ; j++) {
					if (parent[j] == i) {
						deg -= cnt[j];
						hasChild = true;
					}
				}
				best += deg;
				if (hasChild || cnt[i] >= 2) {
					best++;
				}
			}
			int pcnt = 0;
			for (int j = 0 ; j < N ; j++) {
				if (parent[j] == -1) {
					pcnt++;
				}
			}
			best += (pcnt == 1) ? 0 : 1;
			//debug(pcnt,best);
			return best;
		}
		long best = Long.MAX_VALUE;
		for (int pl = 0 ; pl < N ; pl++) {
			if ((done & (1<<pl)) != 0) {
				continue;
			}
			for (int p = 0 ; p < N ; p++) {
				if ((done & (1<<p)) == 0) {
					continue;
				}
				if (a[p] % a[pl] == 0) {
					parent[pl] = p;
					long rev = a[p];
					a[p] /= a[pl];
					best = Math.min(best, doit(done | (1<<pl), a, parent));
					a[p] = rev;
					parent[pl] = -1;
				}
			}
			parent[pl] = -1;
			best = Math.min(best, doit(done | (1<<pl), a, parent));
		}
		return best;
	}

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


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

public class C {

	static final int INF = Integer.MAX_VALUE / 3;
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static int N = 1_000_000;
	static int ROOT = 1_000;
	static boolean[] isPrime = new boolean[N + 1];
	static List<Integer> primes = new ArrayList<>(78498);
	static {
		Arrays.fill(isPrime, true);
		for (int i = 2; i <= N; i++) {
			if (isPrime[i]) {
				primes.add(i);
				if (i <= ROOT) {
					for (int j = i * i; j <= N; j += i) {
						isPrime[j] = false;
					}
				}
			}
		}
	}

	int n;
	long[] a;

	void solve() throws IOException {
		n = nextInt();
		a = new long[n];

		for (int i = 0; i < n; i++) {
			a[i] = nextLong();
		}

		Arrays.sort(a);

		int ans = go(n - 1, new ArrayList<Long>());
		out.println(ans);
	}

	int go(int i, List<Long> vs) {
		if (i == -1) {
			int ret = 0;

			for (long x : vs) {
				int val = sumPrimePowers(x);
				ret += val + 1;
			}

			if (vs.size() > 1)
				ret++;

			return ret;
		}

		int ret = Integer.MAX_VALUE;

		long add = a[i];
		for (int j = 0; j < vs.size(); j++) {
			if (vs.get(j) % add == 0) {
				List<Long> newVs = new ArrayList<>(vs);

				newVs.set(j, vs.get(j) / add);
				if (sumPrimePowers(add) > 1) {
					newVs.add(add);
				} else {
					newVs.add(1L);
				}
				ret = Math.min(ret, go(i - 1, newVs));
			}
		}
		if (sumPrimePowers(add) == 1) {
			vs.add(1L);
		} else {
			vs.add(add);
		}
		ret = Math.min(ret, go(i - 1, vs));
		return ret;
	}

	int sumPrimePowers(long x) {
		int ret = 0;
		for (int i = 0; i < primes.size(); i++) {
			int p = primes.get(i);
			while (x % p == 0) {
				x /= p;
				ret++;
			}
		}
		if (x != 1)
			ret++;
		return ret;
	}

	C() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

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

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


//package codeforces;

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();
		String str = sc.nextLine();
		if (len < 2) {
			System.out.println(str);
		} else {
			String[] str_char = str.split("");
			StringBuffer sb = new StringBuffer("1");
			for (int i = 0; i < str_char.length; i++) {
				if(str_char[i].equals("0")){
					sb.append("0");
				}
			}
			System.out.println(sb);
		}

	}

}


public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int c= scan.nextInt();
            int d = scan.nextInt();
            int n = scan.nextInt();
            int m = scan.nextInt();
            int k = scan.nextInt();
            if(k>=n*m)System.out.println(0);
            else{
                int temp=n*m-k;
                if((double)c/n>d){
                    System.out.println((n*m-k)*d);
                }
                else{
                    int ans=temp/n;
                    int x = ans*c;
                    if(ans*n==temp){
                        System.out.println(x);
                    }
                    else{
                        int t =temp-ans*n;
                        if(t*d<c)x+=t*d;
                        else x+=c;
                        System.out.println(x);
                    }
                }
            }
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import javax.swing.text.html.HTMLDocument.Iterator;

public class HelloWorld {

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		long sum = 0;
		TreeSet<Long> result = new TreeSet<Long>();
		for(int i = 1; i <=a; i++) {
			for(int u = 1; u <= b-1; u++) {
				result.add((long) (u * (i * b + 1)));
			}
		}
		   java.util.Iterator<Long> iterator = result.iterator();
		   while(iterator.hasNext()){
			   long temp = iterator.next();
			   sum+= temp;
	        }
		   System.out.println(sum % 1000000007);
	}
}


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

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

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

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

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

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

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

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

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;
	int m,n;
	long mod = 1000000007;
	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			input();
			solve();
		}
	}
	long[][] dp;
	void solve()
	{
		dp = new long[n+1][m+1];
		for(int i = 1; i<=n;i++)
			for(int j = 1;j<=m;j++)
			{
				if(a.charAt(i-1)==b.charAt(j-1))
					dp[i][j]=(dp[i-1][j-1]+dp[i][j-1]+1)%mod;
				else
					dp[i][j] = dp[i][j-1];

				//debug(i,j,dp[i][j]);
			}
		long count=0;

		for(int i = 0 ;i<=n;i++)
			count=(count+dp[i][m])%mod;
		System.out.println(count);
	}

	void printarr(int [] a,int b)
	{
		for(int i = 0;i<=b;i++)
		{
			if(i==0)
				System.out.print(a[i]);
			else
				System.out.print(" "+a[i]);
		}
		System.out.println();
	}
	String a,b;
	boolean input() throws IOException
	{
		a = nline();
		b = nline();

		n = a.length();
		m = b.length();
		return true;
	}
}


import java.util.Scanner;

public class C294 {

    //static int dp[][];

    static int count(int n, int m, int[][] dp) {

        if(n < 1 || m < 1 || n + m < 3)
            return 0;

        if(dp[n][m] > 0)
            return dp[n][m];

        dp[n][m] = 1 + Math.max(count(n-1, m-2, dp), count(n-2, m-1, dp));

        return dp[n][m];
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

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

        int[][] dp = new int[n][m];

        //double result;

        if(n < 1 || m < 1 || n + m < 3)
            System.out.println(0);
        else {
            int res = 1 + Math.max(count(n-1, m-2, dp), count(n-2, m-1, dp));

            System.out.println(res);
        }

        /*if(n < m) {
            result = m / 2;
            result = Math.min(result, n);
            if(n - result > 1)
                if(m % 2 == 1)
                    result++;
        } else if(n > m) {
            result = n / 2;
            result = Math.min(result, m);
            if(m - result > 1)
                if(n % 2 == 1)
                    result++;
        } else {
            result = n + m;
            result /= 3;
        }

        System.out.println((int)result);*/

        sc.close();

    }
}


import java.util.Scanner;

public class Class1 {
	public static void main(String[]	args) {
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		int[] arr1=new int[n];
		for(int i=0;i<n;i++)
			arr1[i]=input.nextInt();
		int[] arr2=new int[n];
		for(int i=0;i<n;i++)
			arr2[i]=input.nextInt();
		input.close();
		int counter=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(arr2[j]==arr1[i]||arr2[j]==0) {
					counter++;
					break;
				}

			}
		}
		if(counter==n)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


import java.util.Scanner;

public class Ivan{

  public static boolean check(long s,long n){
    long big = 0;
    long u = s;
    while (s >= 1){
      big =big + s % 10;
      s = (s - big) / 10;
    }
    if (u - big > n){
      return true;
    }else return false;
  }

  public static long analyze(long n){
    return n/9;
  }
  public static long number(long x){
    return x*9;
  }

  public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      long s = scan.nextLong();
      long n = scan.nextLong();
      long r =0;
      for (long i = n;i<s+1;i++){
        if (check(i,n)){
          r=i;
          break;
        }else r = s+1;
      }
      System.out.print(s-r+1);
    }
  }
}


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.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

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

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

	class State{

	}

	// solution
	private void solve() throws Throwable {

		int n = iread();
		Hashtable[] tables = new Hashtable[n];

		out.flush();
	}

	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.equalsIgnoreCase("input")){
					break;
				}
				while (true) {
					readLine = testdataReader.readLine();
					if(readLine.equalsIgnoreCase("output")){
						break;
					}
					w.write(readLine + "\n");
				}
				w.close();
				System.out.println("Answer on case "+(++casenr)+": ");

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

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

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

	public C134() 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 AmityAssesment {

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

		Scanner input = new Scanner(System.in);
		String a = input.next();
	   a+=reverse(input.next());
	   String b = input.next();
	   b+=reverse(input.next());
	   if(a==b){
		   System.out.println("YES");
	     return;
	   }
	     String p=a;
	   a = next(a);
	  //System.out.println(b+" "+a);
	  while(!p.equals(a)){
		 // System.out.println(a+" "+b);
		  if(a.equals(b)){
			  System.out.println("YES");
		     return;
		  }
		  a = next(a);
	  }
	  System.out.println("NO");
	}

	private static String reverse(String s){
		String z = "";
		for(int i=s.length()-1; i>=0;i--)z+=s.charAt(i);
		return z;
	}

	private static String next(String s){
		int i = s.indexOf("X");
		String z = "";
		if(i!=s.length()-1){
			z+=s.substring(0,i);
		z+=reverse(s.substring(i,i+2));
		z+=s.substring(i+2);
			return z;
		}
		else{
			z+=s.charAt(s.length()-1)+s.substring(1,s.length()-1)+s.charAt(0);
			return z;
		}
	}

}


package hello;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

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

	private static void soln() {
		char[][] board = new char[4][4];
		for(int i = 0; i < 4; i++) {
			board[i] = nLi().toCharArray();
		}

		boolean isWilling = false;
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 4; j++) {
				if(isWinningRow(board, i, j) || isWinningColumn(board, i, j) || isWinningDiagonal(board, i, j))
				{
					// pw.println(isWinningRow(board, i, j));
					// pw.println(isWinningColumn(board, i, j));
					// pw.println(isWinningDiagonal(board, i, j));
					// pw.println(i + " " + j);
					isWilling = true;
					break;
				}
			}
			if(isWilling)
				break;
		}
		if(isWilling)
			pw.println("YES");
		else
			pw.println("NO");
	}

	private static boolean isWinningRow(char[][] board, int i, int j) {
		// TODO Auto-generated method stub
		if(j == 2 || j == 3)
			return false;
		if(board[i][j] != 'x')
			return false;
		// already x
		if(board[i][j] == board[i][j + 1] && board[i][j] == board[i][j + 2])
			return true;
		// count dots
		int dots = 0;
		for(int x = j; x <= (j + 2); x++) {
			if(board[i][x] == 'o')
				return false;
			if(board[i][x] == '.')
				dots++;
		}
		if(dots == 1)
			return true;
		return false;
	}

	private static boolean isWinningColumn(char[][] board, int i, int j) {
		// TODO Auto-generated method stub
		if(i == 2 || i == 3)
			return false;
		if(board[i][j] != 'x')
			return false;
		if(board[i][j] == board[i + 1][j] && board[i][j] == board[i + 2][j])
			return true;// count dots
		int dots = 0;
		for(int x = i; x <= (i + 2); x++) {
			if(board[x][j] == 'o')
				return false;
			if(board[x][j] == '.')
				dots++;
		}
		if(dots == 1)
			return true;
		return false;
	}

	private static boolean isWinningDiagonal(char[][] board, int i, int j) {
		if(i == 2 || i == 3)
			return false;
		if(j == 2 || j == 3)
			return false;
		if(board[i][j] != 'x')
			return false;
		if(board[i][j] == board[i+1][j + 1] && board[i][j] == board[i + 2][j + 2])
			return true;
		// count dots
		int dots = 0;
		for(int x = 1; x <=  2; x++) {
			if(board[i + x][j + x] == 'o')
				return false;
			if(board[i + x][j + x] == '.')
				dots++;
		}
		if(dots == 1)
			return true;
		return false;
	}

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

	public static long pow(long x, long y, long m) {
		if (y == 0)
			return 1;
		long k = pow(x, y / 2, m);
		if (y % 2 == 0)
			return (k * k) % m;
		else
			return (((k * k) % m) * x) % m;
	}

	static long Inversex = 0, Inversey = 0;

	public static void InverseModulo(long a, long m) {
		if (m == 0) {
			Inversex = 1;
			Inversey = 0;
		} else {
			InverseModulo(m, a % m);
			long temp = Inversex;
			Inversex = Inversey;
			Inversey = temp + -(a / m) * Inversey;
		}
	}

	static long mod1 = 1000000007;
	static long mod2 = 1000000009;

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

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;
		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	public static double distance(int a, int b, int x, int y) {
		return Math.sqrt(((long) (a - x) * (long) (a - x)) + ((long) (b - y) * (long) (b - y)));
	}

	public static int seive(int a[], boolean b[], ArrayList c) {
		int count = 0;
		for (int i = 2; i * i < a.length; i++) {
			if (!b[i]) {
				for (int j = i * i; j < a.length; j = j + i)
					b[j] = true;
				c.add(i);
				a[count++] = i;
			}
		}
		return count;
	}

	// To Get Input
	// Some Buffer Methods
	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

	public static class Queue {
		private class node {
			int val;
			node next;

			node(int a) {
				val = a;
				next = null;
			}
		}

		node head, tail;

		Queue() {
			head = null;
			tail = null;
		}

		public void EnQueue(int a) {
			if (head == null) {
				node p = new node(a);
				head = p;
				tail = p;
			} else {
				node p = new node(a);
				tail.next = p;
				tail = p;
			}
		}

		public int DeQueue() {
			int a = head.val;
			head = head.next;
			return a;
		}

		public boolean isEmpty() {
			return head == null;
		}
	}

	public static class Pair implements Comparable<Pair> {
		long u;
		long v;
		BigInteger bi;

		public Pair(long u, long v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//Joty and Chocolate
		Scanner in = new
				Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int p = in.nextInt();
		int q = in.nextInt();
		int total = 0;
		long []vector = new long [n+1];
		if (p>q)
		{
			for (int i = a; i <= n; i=i+a)
			{
				if (vector[i]==0)
				{
					vector[i]=2;
					total += p;
				}
			}
			for (int i = b; i <= n; i=i+b)
			{
				if (vector[i]==0)
				{
					vector[i]=1;
					total += q;
				}
			}
		}
		else
		{
			for (int i = b; i <= n; i=i+b)
			{
				if (vector[i]==0)
				{
					vector[i]=2;
					total += q;
				}
			}
			for (int i = a; i <= n; i=i+a)
			{
				if (vector[i]==0)
				{
					vector[i]=1;
					total += p;
				}
			}
		}
		System.out.println(total);

	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class q2 {
    public static void main(String[] args) {
        ArrayList<Double> arr = new ArrayList<>();
        Integer res = 0;
        Scanner scanner = new Scanner(System.in);
        for (int i = 0 ; i<5 ; i++){
            arr.add(scanner.nextDouble());}
        double dist = arr.get(4);
        double vp = arr.get(0);
        double vd = arr.get(1);
        double delay = arr.get(2);
        double f = arr.get(3);
        double dd = 0;
        double dp = delay*vp;
        double ttap = dist/vp;
        double i = delay;
        while (i<ttap){
            if (dd>= dp){
                res++;
                double ttfd = (dp/vd)+f;
                dp = dp+ttfd*vp;
                dd = 0;
                i += ttfd;
            }
            else {
                double t = (dp-dd)/(vd-vp);
                i+=t;
                dd += t*vd;
                dp+= t*vp;

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


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

public class test
{

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

        String s[] = br.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);

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

        for(int i=2;i<=n;i++)
        {
            for(int j=2;j<=m;j++)
            {
                int max = Math.max(i,j);
                if(max==i)
                {
                    dp[i][j] = dp[i-2][j-1]+1;
                }
                else if(max==j)
                {
                    dp[i][j] = dp[i-1][j-2]+1;
                }
            }
        }

        System.out.println(dp[n][m]);

    }

}


import java.util.*;
public class BearAndMatch
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] t = new int[n];
for(int i = 0;i < n;i++)
{
      t[i] = sc.nextInt();
      if(t[0] > 15)
      {
            System.out.println(15);
            return;
      }
}
if(n==1 && t[0]<=15)
{
      System.out.println(t[0]+15);
      return;
}
int ct = 0;
for(int i = 0;i < n-1;i++)
{
      if(Math.abs(t[i]-t[i+1]) > 15)
      {
            if(t[i]+15 < 90)
            {
            System.out.println(t[i]+15);
            return;
            }
            else if(t[i]+15 >= 90)
            {
                  System.out.println(90);
                  return;
            }
      }
      else
      {
            ct++;
      }
}
      System.out.println(90);
      return;
}
}


import java.util.PriorityQueue;
import java.util.Scanner;

public class q5 {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int k = scn.nextInt();
		PriorityQueue<Integer> mt = new PriorityQueue<>();
		mt.add(n);
		mt.add(m);
		mt.add(k);
		int st = 0;
		StringBuilder sb = new StringBuilder();

		while (n>0||m>0||k>0) {
			int val = Math.max(n, Math.max(m, k));
			if (val == n&&val>0) {
			  if(sb.length()>=2){
				  char ch=sb.charAt(sb.length()-1);
				  char ch2=sb.charAt(sb.length()-2);
				  if(ch!='n'||ch2!='n'){
					  sb.append("n");
					  n-=1;
				  }else{
					 int vs=    Math.max(m,k);
					 if(vs==m&&vs>0){
						 sb.append("m");
						 m--;
					 }else if(vs==k&&vs>0){
						 sb.append("k");
						 k--;
					 }
				  }
			  }else{
				  sb.append("n");
				  n-=1;
			  }
			} else if (val == m&&val>0) {
				if(sb.length()>=2){
					  char ch=sb.charAt(sb.length()-1);
					  char ch2=sb.charAt(sb.length()-2);
					  if(ch!='m'||ch2!='m'){
						  sb.append("m");
						  m-=1;
					  }else{
						 int vs=    Math.max(n,k);
						 if(vs==n&&vs>0){
							 sb.append("n");
							 n--;
						 }else if(vs==k&&vs>0){
							 sb.append("k");
							 k--;
						 }else{
							 break;
						 }
					  }
				  }else{
					  sb.append("m");
					  m-=1;
				  }
			} else  if(val==k&&val>0){
				if(sb.length()>=2){
					  char ch=sb.charAt(sb.length()-1);
					  char ch2=sb.charAt(sb.length()-2);
					  if(ch!='k'||ch2!='k'){
						  sb.append("k");
						  k-=1;
					  }else{
						 int vs=    Math.max(m,n);
						 if(vs==n&&vs>0){
							 sb.append("n");
							 n--;
						 }else if(vs==m&&vs>0){
							 sb.append("m");
							 m--;
						 }else{
							 break;
						 }
					  }
				  }else{
					  sb.append("k");
					  k-=1;
				  }
			}
		}

		System.out.println(sb.length()/3);
	}

}


import java.util.Scanner;

/**
 * Created by peter.bykov on 19.05.2014.
 */
public class Archive387A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] now = s.nextLine().split(":");
        String[] sleepTime = s.nextLine().split(":");
        int hours = Integer.parseInt(now[0]) - Integer.parseInt(sleepTime[0]);
        if(hours < 0) {
            hours = 24 + hours;
        }
        int minutes = Integer.parseInt(now[1]) - Integer.parseInt(sleepTime[1]);
        if(minutes < 0) {
            if(hours > 0) {
                --hours;
            } else {
                hours = 23;
            }
            minutes = 60 + minutes;
        }
        System.out.println(((hours>=10)?hours:"0"+hours) + ":" + ((minutes>=10)?minutes:"0"+minutes));

    }


import java.util.*;
public class ChatRecord {

    public static int searchstring(String s,String S){
        if (s.length()>S.length())
            return -1;
        for(int i=0;i<=(S.length()-s.length());i++){
            if (s.equals(S.substring(i,i+s.length())))
                return i;
        }
        return -1;
    }

    public static boolean geometric(int x , int y , int z , int w){
        if (x == 0 || z==0 || y==0 || w==0){

            return false;
        }

        double a =y/x;

        double b =z/y;
        double c =w/z;
        if (a==b && b==c)
            return true;
        return false;
    }
    public static void main(String[] args){
        String I = "1";
        while (! I.equals("0")){
        Scanner sc = new Scanner(System.in);
        String Input = sc.nextLine();
        int space = searchstring(" ",Input);

        int x = Integer.parseInt(Input.substring(0,space));
        Input = Input.substring(space+1, Input.length());
        space = searchstring(" ",Input);
        int y = Integer.parseInt(Input.substring(0,space));
        Input = Input.substring(space+1, Input.length());
        space = searchstring(" ",Input);
        int z = Integer.parseInt(Input.substring(0,space));
        Input = Input.substring(space+1, Input.length());
        space = searchstring(" ",Input);
        int w = Integer.parseInt(Input.substring(0,Input.length()));

        if ((y-x)==(z-y) && (z-y)==(w-z)){
            System.out.println(y-x+w);
            return;
        }
        else if (geometric(x,y,z,w)){
            if (x == 0 || y/x==1 || z==0 || y==0 || w==0){
                System.out.println("42");
                return;
            }

            if ((w*w)%z == 0)
                    System.out.println(w*w/z);
            else System.out.println(42);
        }
            else
                System.out.println(42);
        I = sc.nextLine();
        }

    }
}


/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/24/11
 * Time: 8:54 PM
 * To change this template use File | Settings | File Templates.
 */

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

public class TaskD extends Thread {

    public TaskD() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    static class Matrix {
        long[][] grid;
        long[][] helper;

        public Matrix(int size, boolean E) {
            this.grid = new long[size][size];
            this.helper = new long[size][size];
            if (E) {
                for (int i = 0; i < grid.length; ++i) {
                    grid[i][i] = 1;
                }
            }
        }

        public Matrix pow(long power) {
            Matrix result = new Matrix(grid.length, true);
            Matrix stat = new Matrix(grid.length, false);
            for (int i = 0; i < grid.length; ++i) {
                stat.grid[i] = this.grid[i].clone();
            }
            while (power != 0) {
                if ((power & 1) == 1) {
                    result.multiply(stat);
                    --power;
                } else {
                    stat.multiply(stat);
                    power >>= 1;
                }
            }
            return result;
        }

        private void multiply(Matrix another) {
            for (long[] current : helper) {
                Arrays.fill(current, 0);
            }
            for (int i = 0; i < grid.length; ++i) {
                for (int j = 0; j < grid.length; ++j) {
                    for (int k = 0; k < grid.length; ++k) {
                        helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;
                    }
                    helper[i][j] %= MODULO;
                }
            }
            for (int i = 0; i < grid.length; ++i) {
                System.arraycopy(helper[i], 0, grid[i], 0, grid.length);
            }
        }
    }

    static class Rule {
        char letter;
        char value;

        public Rule(char letter, char value) {
            this.letter = letter;
            this.value = value;
        }
    }

    private void generate(int index) {
        if (index == initial.length) {
            states[SIZE++] = initial.clone();
        } else {
            for (char value = 0; value < rules[index].value; ++value) {
                initial[index] = value;
                generate(index + 1);
            }
        }
    }

    private boolean isFinal(int index) {
        for (char letter = 'A'; letter <= 'Z'; ++letter) {
            boolean was = false, isGood = false;
            for (int i = 0; i < rules.length; ++i) {
                if (rules[i].letter == letter) {
                    was = true;
                    isGood |= states[index][i] == 0;
                }
            }
            if (was && !isGood) {
                return false;
            }
        }
        return true;
    }

    private void solve() throws Throwable {
        long n = nextLong();
        int c = nextInt();
        int s = c;
        c = 0;
        rules = new Rule[s];
        int total = 1;
        for (c = 0; c < s;) {
            rules[c] = new Rule(nextToken().charAt(0), (char) (nextInt()));
            boolean was = false;
            for (int q = 0; q < c; ++q) {
                if (rules[q].letter == rules[c].letter && rules[q].value == rules[c].value) {
                    was = true;
                    break;
                }
            }
            if (!was){
                total *= rules[c++].value;
            }
        }
        initial = new char[c];
        states = new char[total][];
        generate(0);
        Matrix operator = new Matrix(total, false);
        for (int from = 0; from < total; ++from) {
            for (char letter = 'A'; letter <= 'Z'; ++letter) {
                boolean isPresent = false;
                char []helper = states[from].clone();
                for (int i = 0; i < c; ++i) {
                    if (rules[i].letter == letter) {
                        isPresent = true;
                        helper[i] = (char)((helper[i] + 1) % rules[i].value);
                    }
                }
                if (isPresent) {
                    for (int to = 0; to < states.length; ++to) {
                        boolean ok = true;
                        for (int index = 0; index < c; ++index) {
                            ok &= states[to][index] == helper[index];
                        }
                        if (ok) {
                            operator.grid[from][to]++;
                            break;
                        }
                    }
                }
            }
        }

        Matrix finish = operator.pow(n);
        long result = 0;
        for (int current = 0; current < total; ++current) {
            if (isFinal(current)) {
                result = (result + finish.grid[0][current]) % MODULO;
            }
        }
        output.println(result);
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

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

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

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

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

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

    private int SIZE = 0;
    private static final int MODULO = 12345;
    private char[][] states;
    private char[] initial;
    private Rule[] rules;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}


/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/24/11
 * Time: 8:54 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.Arrays;

public class TaskD extends Thread {

    public TaskD() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    private int getHash(int []toHash) {
        int result = toHash[0] * 93 + toHash[toHash.length - 1] * 31;
        result = (result >>> 27) ^ result;
        return result + Arrays.hashCode(toHash);
    }

    private void generate(int index) {
        if (index == helper.length) {
            states[SIZE++] = helper.clone();
            f.put(getHash(helper), SIZE);
        } else {
            for (int value = 0; value < v[index]; ++value) {
                helper[index] = value;
                generate(index + 1);
            }
        }
    }

    private int [][]pow(int [][]src, long power) {
        int [][]result = new int[src.length][src.length];
        for (int i = 0; i < result.length; ++i) {
            result[i][i] = 1;
        }
        for (; power != 0; power >>= 1) {
            if ((power & 1) == 1) {
                result = multiply(result, src);
            }
            src = multiply(src, src);
        }
        return result;
    }

    private int[][]multiply(int [][]left, int [][]right) {
        int [][]result = new int[left.length][left.length];
        for (int i = 0; i < left.length; ++i) {
            for (int j = 0; j < left.length; ++j) {
                for (int k = 0; k < left.length; ++k) {
                    result[i][j] += (left[i][k] * right[k][j]) % MODULO;
                }
                result[i][j] %= MODULO;
            }
        }
        return result;
    }

    private void solve() throws Throwable {
        long n = nextLong();
        int c = nextInt();
        Map<Integer, Integer> f = new HashMap<Integer, Integer>();
        l = new int[c];
        v = new int [c];
        boolean []used = new boolean[AlPHABET_SIZE], good = new boolean[AlPHABET_SIZE];

        int total = 1;
        for (int i = 0; i < c; ++i) {
            l[i] = nextToken().charAt(0) - 'A';
            used[l[i]] = true;
            total *= (v[i] = nextInt());
        }
        states = new int[total][];
        helper = new int[c];
        generate(0);
        int [][]grid = new int[total][total];
        for (int current = 0; current < total; ++current) {
            helper = states[current].clone();
            for (int i = 0; i < AlPHABET_SIZE; ++i) {
                if (used[i]) {
                    for (int ind = 0; ind < c; ++i) {
                        if (l[ind] == i) {
                            helper[ind] = (helper[ind] + 1) % v[ind];
                        }
                    }
                    grid[current][f.get(getHash(helper))]++;
                }
            }
        }
        int [][]result = pow(grid, n);
        int answer = 0;
        for (int currentState = 0; currentState < total; ++currentState) {
            Arrays.fill(good, false);
            for (int i = 0; i < c; ++i) {
                good[l[i]] |= states[currentState][i] == 0;
            }
            boolean can = true;
            for (int i = 0; i < AlPHABET_SIZE; ++i) {
                if (used[i] && ! good[i]) {
                    can = false;
                    break;
                }
            }
            if (can) {
                answer  = (answer + result[0][currentState]) % MODULO;
            }
        }
        output.println(answer);
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

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

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

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

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

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

    private static int [][]states;
    private int []helper, l, v;
    private static int SIZE = 0;
    private static Map<Integer, Integer> f = new HashMap<Integer, Integer>();
    private static final int MODULO = 12345, AlPHABET_SIZE = 26;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}