public class CodeForce{

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

        String Sn=buffer.readLine();
        String Sa=buffer.readLine();
        int n=Integer.parseInt(Sn);
        int a=Integer.parseInt(Sa);
        int count=1;
        if(!((1<=a) && (a<=n) && n<=100000)) {System.out.println("Error"); return; }
        if(n%2==0)
            for(int i=1; i<n-1;i+=2)
            {if(a==i) break;
                else count++;}
        else
                for (int i=n;i<2;i-=2)
                { if(a==i) break;
                        else count++;}
        System.out.println(count);
    }
}


import java.util.*;

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

	  Scanner kbd = new Scanner(System.in);
	  int a = kbd.nextInt();
	  int b = kbd.nextInt();
	  int c

	  if(a>b){
	      c = a-b;
	  }else{
	      c = b-a;
	  }

      System.out.print(c);

	 }

}


public class MainTestClass {
	public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int l = scan.nextInt();
			int u = scan.nextInt();
			int l1 = l/2;
			int[] a = new int[l1];
			int[] b = new int[l1];
			int c = 0;
			boolean bool = false;
			int y = 1;
			for (int i = 1;i<l+1;i++){
				if (bool){
					b[b.length-y] = i;
					bool= false;
					y +=1;
				}else{
					a[i-y] = i;
					bool=true;
				}
			}
			for (int i = 0;i < a.length;i++){
				c = c + 1;
				if (a[i] == u | b[i] == u){
					break;
				}
			}
			System.out.print(c);
		}
}


/*
 * 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.
 */
package codeforce;
/* package whatever; // don't place package name! */

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

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args)
	{
		// your code goes here
		int a,b,t=1,c=1;
		Scanner in =new Scanner (System.in);
		a=in.nextInt();
		b=in.nextInt();
		if(b%2==0)
		{

		while(a!=b)
		{
			a=a-2;
			t=t+1;
		}
		}
		else
		{

			while(c!=b)
			{
				c=c+2;
				t=t+1;
			}
		}
		System.out.println(t);
	}
}


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

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

    static class DIlyaAndEscalator {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            double p = nd();
            int t = ni();
            double[][] E = new double[n + 1][t + 1];
            E[1][1] = p;
            int i = 0, j = 0;
            for (i = 2; i <= t; i++)
                E[1][i] = E[1][i - 1] + p * Math.pow(1 - p, i - 1);
            for (i = 2; i <= n; i++)
                E[i][1] = E[i - 1][1];
            for (i = 2; i <= n; i++) {
                for (j = 2; j <= t; j++)
                    E[i][j] = E[i - 1][j - 1] * p;
            }
            pn(E[n][t]);
        }

        int ni() {
            return in.nextInt();
        }

        double nd() {
            return in.nextDouble();
        }

        void pn(Object o) {
            out.println(o);
        }

    }

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

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

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

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

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

            return res.toString();
        }

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

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

    }
}


import java.scanner;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double p = scan.nextDouble();
		int t = scan.nextInt();
		double ans = 0;
		for(int i = 0;i<=n;i++){
			ans += solve(n,i,p);
		}
		System.out.println(ans);
	}
	static double solve(int n,int x,double p){
		return Math.pow(p,x)*Math.pow((1-p),(n-x))*x;
	}
}


import java.Scanner;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double p = scan.nextDouble();
		int t = scan.nextInt();
		double ans = 0;
		for(int i = 0;i<=n;i++){
			ans += solve(n,i,p);
		}
		System.out.println(ans);
	}
	static double solve(int n,int x,double p){
		return Math.pow(p,x)*Math.pow((1-p),(n-x))*x;
	}
}


import java.scanner;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double p = scan.nextDouble();
		int t = scan.nextInt();
		double ans = 0;
		for(int i = 0;i<=n;i++){
			ans += solve(n,i,p);
		}
		System.out.println(ans);
	}
	static double solve(int n,int x,double p){
		return Math.pow(p,x)*Math.pow((1-p),(n-x)*x;
	}
}


package Codes;

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

public class CIvanTheFoolAndTheProbabilityTheory {
    static int r,c,mod=(int)1e9+7,k;
    static Integer memo[][][];
    public void solve(int testNumber, Scanner sc, PrintWriter pw) {
         r=sc.nextInt();
         c=sc.nextInt();
         k=Math.max(r,c);
         memo=new Integer[3][3][k+1];
        pw.println((dp(0,0,0)+(Math.min(r,c)==2?2:0))%mod);
    }

    private int dp(int i, int white,int black) {
        if(i==k)
            return 1;
        if(memo[white][black][i]!=null)
            return memo[white][black][i];
        int blackk=0,whitee=0;
        if(black<2)
            blackk = dp(i+1,0,black+1);
        if(white<2)
            whitee=dp(i+1,white+1,0);
        return memo[white][black][i]=((blackk+whitee)%mod);
    }
}


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

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

    static class CIvanTheFoolAndTheProbabilityTheory {
        static int r;
        static int c;
        static int mod = (int) 1e9 + 7;
        static Integer memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            r = sc.nextInt();
            c = sc.nextInt();
            memo = new Integer[3][3][c + 1];
            pw.println((dp(0, 0, 0) + (r == 2 ? 2 : 0)) % mod);
        }

        private int dp(int i, int white, int black) {
            if (i == c)
                return 1;
            if (memo[white][black][i] != null)
                return memo[white][black][i];
            int blackk = 0, whitee = 0;
            if (black < 2)
                blackk = dp(i + 1, Math.max(0, white - 1), black + 1);
            if (white < 2)
                whitee = dp(i + 1, white + 1, Math.max(0, black - 1));
            return memo[white][black][i] = (blackk + whitee) % mod;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

    }
}


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

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

    static class CIvanTheFoolAndTheProbabilityTheory {
        static int r;
        static int c;
        static int mod = (int) 1e9 + 7;
        static int k;
        static Integer memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            r = sc.nextInt();
            c = sc.nextInt();
            k = Math.max(r, c);
            memo = new Integer[3][3][k + 1];
            pw.println((dp(0, 0, 0) + (Math.min(r, c) == 2 ? 2 : 0)) % mod);
        }

        private int dp(int i, int white, int black) {
            if (i == k)
                return 1;
            if (memo[white][black][i] != null)
                return memo[white][black][i];
            int blackk = 0, whitee = 0;
            if (black < 2)
                blackk = dp(i + 1, 0, black + 1);
            if (white < 2)
                whitee = dp(i + 1, white + 1, 0);
            return memo[white][black][i] = ((blackk + whitee) % mod);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

    }
}


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

public class CF {

  static int n, m;
  static int mod=(int)1e9+7;
  static int ans[] = new int[100001];

  static void solve() {
    ans[0] =1 ;
    ans[1] =1 ;
    ans[2] =2;
    for (int i = 3; i < 100001; i++)
      ans[i] =( ans[i - 1] %mod + ans[i - 2] %mod) % mod;
  }

  public static void main(String[] arg) throws Exception{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String s[] = bf.readLine().trim().split("\\s+");
    n = Integer.parseInt(s[0]);
    m = Integer.parseInt(s[1]);
    solve();
    System.out.println((2 * (ans[n] + ans[m] - 1)5mod)%mod);
  }
}


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

public class Main implements Runnable {
    final int MAXP = 10000000;

    boolean mark[] = new boolean[MAXP];

    public void run() {
        int a = nextInt(), b = nextInt(), mod = nextInt();

        if (b >= mod-1) { output.println(2); output.flush(); return; }

        int cur = 0;

        for (int i = 1; ; ++i) {
            cur = (cur + 1000000000) % mod;

            if (mark[cur]) break;
            mark[cur] = true;

            if (cur > 0 && cur+b < mod) {
                output.print(1 + " ");

                int add = 9 - new Integer(i).toString().length();
                for (int j = 0; j < add; ++j) output.print("0");
                output.println(i);

                output.flush();
                return;
            }
        }

        output.println(2);
        output.flush();
    }

    public static void main(String[] args) {
        //try { input = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } catch (Exception e) {}
        new Main().run();
    }

    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter output = new PrintWriter(System.out);
    StringTokenizer tokenizer = null;

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

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

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

    String nextToken() {
        try
        {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(input.readLine());
            }

            return tokenizer.nextToken();
        } catch (Exception e) {
            return null;
        }
    }
}


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

public class B {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    final int MULT = 1000000000;

    void solve() throws IOException {
        int a = nextInt();
        int b = nextInt();

        int mod = nextInt();

        int aMult = MULT % mod;

        if (mod == 1) {
            out.print(2);
            return;
        }

        int maxBRem = Math.min(b, mod - 1);

        for (int i = 0; i < mod; i++) {
            int aRem = (int) ((long)i * aMult % mod);
            if (aRem == 0 || aRem + maxBRem >= mod)
                continue;
            out.printf("1 %09d", i);
            return;
        }

        out.print(2);

    }

    void inp() 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 B().inp();
    }

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

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

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

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

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

}


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

public class Solution implements Runnable{
    public static BufferedReader br;
    public static PrintWriter out;
    public static StringTokenizer stk;
    public static boolean isStream = true;

    public static void main(String[] args) throws IOException {
    	if (isStream) {
            br = new BufferedReader(new InputStreamReader(System.in));
        } else {
            br = new BufferedReader(new FileReader("in.txt"));
        }
        out = new PrintWriter(System.out);
        new Thread(new Solution()).start();
    }

    public void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

    public String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return stk.nextToken();
    }

    public Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.valueOf(stk.nextToken());
    }

    public Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.valueOf(stk.nextToken());
    }

    public Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.valueOf(stk.nextToken());
    }

    public Float nextFloat() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Float.valueOf(stk.nextToken());
    }

    public void run() {
    	int a = nextInt();
    	int b = nextInt();
    	int mod = nextInt();
    	int bnd = Math.min(a, mod);
    	int ans = -1;
    	for (int i = 0; i < bnd; i++) {
    		long aa = i*1000000000L%mod;
    		int rem = (int)aa;
    		if (rem != 0 && mod-rem > b) {
    			ans = i;
    			break;
    		}
    	}
    	if (ans >= 0) {
    		StringBuilder sb = new StringBuilder();
    		for (int i = 0; i < 9; i++) {
    			sb.append(ans%10);
    			ans/=10;
    		}
    		out.println(1+" "+sb.reverse().toString());
    	} else {
    		out.println(2);
    	}
    	out.flush();
    }
}


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

public class Game {
  public static void main(String[] args) throws IOException {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String[] input = bf.readLine().split(" ");
    String answer = "";
    int a, b, mod, ans;
    boolean oneWins = false;
    a = Integer.parseInt(input[0]);
    b = Integer.parseInt(input[1]);
    mod = Integer.parseInt(input[2]);

    for (ans = 1; ans <= a; ans++) {
      if ((mod - (ans *1000000000)) % mod > b) {
          oneWins = true;
          break;
      }
    }

    if (oneWin) {
      String temp = String.valueOf(ans);
      int digits = temp.length();
      for (int i = 0;i < 9 - digits; i++) {
        answer += "0";
      }
      answer += String.valueOf(ans);
      System.out.println("1 " + answer);
    } else {
      System.out.println(2);
    }
  }
}


import java.util.*;

public class Sample {

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n+1];
		int max = Integer.MIN_VALUE;
		for(int i = 0; i <= 9; i++){
			if(i > n) break;
			arr[i] = i;
			if(arr[i] > max) max = arr[i];
		}
		if(n >= 10) arr[10] = 0;
		for(int i = 11; i <= n; i++){
			String iSub = Integer.toString(i);
			String iSubLast = iSub.substring(0,iSub.length() - 1);
			arr[i] = arr[Integer.parseInt(iSubLast)] * Integer.parseInt(iSub.substring(iSub.length() - 1, iSub.length()));
			if(arr[i] > max) max = arr[i];
		}
		System.out.println(max);

	}
}


// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
	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;
		}
	}

	public static void main(String[] args) {
		FastReader in=new FastReader();
		int n = in.nextInt();

		try{
			BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
			if(n < 10){
				log.write(n);
			}else{
				n--;
				String s = n;
				String [] digits = s.toCharArray();
				long product = 1;
				for(char c: digits){
					product *= c-'0';
				}
				log.write();
			}

			log.flush();
			log.close();
		}catch(IOException e){

		}
	}
}


import java.util.Scanner;

public class Nirvana {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Nirvana obj = new Nirvana();
		System.out.println(obj.maxMultiply(n));

		in.close();
	}
	int maxMultiply(int n) {
		if(n == 0)
			return 1;
		int nextNum = n/10;
		int digit = n%10;
		if(digit == 9) {
			// No need to borrow
			return 9*maxMultiply(nextNum);
		}
		int result9 = -1;
		int resultNormal = -1;
		if(nextNum>0) {
			// Can borrow
			result9 = 9*maxMultiply(nextNum-1);
		}
		resultNormal = digit*maxMultiply(nextNum);
		return Math.max(result9, resultNormal);
	}

}


package code;

import IO.InputReader;
import IO.OutputWriter;
import java.io.IOException;

public class BNirvana {
    public void solve(int testNumber, InputReader in, OutputWriter out) throws IOException {
        long n=in.nextLong();
        String S=String.valueOf(n);
        long ans=Math.max(calVal(n-1),calVal(n-2));
        if(n<10)
            out.printLine(n-1);
        else
        {
            ans=Math.max(ans,(long)Math.pow(9,S.length()-1));
            for(int i=1;i<S.length();i++)
                ans=Math.max(ans,calVal(((n/(long)Math.pow(10,i))*(long)Math.pow(10,i))-1));
            //out.printLine(calVal(((n/(long)Math.pow(10,i))*(long)Math.pow(10,i))-1));
            out.printLine(ans);
        }
    }
    long calVal(long x)
    {
        if(x==0)
            return 1;
        else
            return x%10*calVal(x/10);
    }
}


import java.util.*;

public class R0_task_C {
    static int n,s,k;
    static int[]r;
    static char[]c;

    static box[] allBoxes;

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

        n = in.nextInt();
        s = in.nextInt();
        k = in.nextInt();

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

        c = new char[n+1];
        String st = "*" + in.next();
        c = st.toCharArray();
        //-------------

        allBoxes = new box[n+1];
        for (int i=0; i<=n; i++)
            allBoxes[i] = new box(i, 0, false);
        Arrays.sort(allBoxes);

        allBoxes[0] = new box(0, 0,true);

        //int t = fullScan(0, 0, k);
        int t = allBoxes[0].eat(0, k);
        System.out.println(t);
    }
/*
    static int fullScan(int from, int time, int restCount){
        if (restCount <= 0)
            return time;

        int minTime = -1;
        for (int to = 1; to <= n; to++) {
            if (enabled(from, to)) {
               int curTime = from == 0 ? Math.abs(s - to) : Math.abs(from - to);
               int restTime = fullScan(to, time + curTime, restCount - r[to]);
               if (restTime >= 0)
                    if (restTime < minTime || minTime == -1)
                        minTime = restTime;
            }
        }
        return minTime;
    }
*/
    static boolean enabled(int from, int to){
        return r[from] < r[to] && c[from] != c[to];
    }

    static class box implements Comparable<box>{

        int idx;
        ArrayList<box> nexts = new ArrayList<>();

        public box(int idx, int order, boolean initNexts) {
            this.idx = idx;
            if (initNexts){
                boolean hasNext = false;
                //for (int target = 1; target <= n; target++){
                for (int next = order+1; next <= n; next++) {
                    int target = allBoxes[next].idx;
                    if (enabled(idx, target)) {
                        //if (allBoxes[next] == null)
                            allBoxes[next] = new box(target, next, true);
                        nexts.add(allBoxes[next]);
                        hasNext = true;
                    }
                }
                /*if (hasNext)//!nexts.isEmpty())
                    Collections.sort(nexts);*/
            }
        }

        int eat(int time, int restCount){
            if (restCount <= 0)
                return time;

            int from = idx;
            int minTime = -1;

            for (box b: nexts) {
                int to = b.idx;
                int curTime = from == 0 ? Math.abs(s - to) : Math.abs(from - to);
                int restTime = b.eat( time + curTime, restCount - r[to]);
                if (restTime >= 0)
                    if (restTime < minTime || minTime == -1)
                        minTime = restTime;
            }
            return minTime;
        }

        @Override
        public int compareTo(box o) {
            return r[this.idx] - r[o.idx];
        }
    }
}


import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class A {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

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

	public class Pair implements Comparable<Pair> {
		int x;
		int y;

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

		public int compareTo(Pair o) {
		    if (x != o.x) {
		        return x - o.x;
		    }
		    return y - o.y;
		}
	}

	public void solve() {
		int n = in.nextInt();
		int start = in.nextInt() - 1;
		int k = in.nextInt();
		Pair[] a = new Pair[n];
		int[] sweet = new int[n];
		TreeMap<Integer, Integer>[] map = new TreeMap[n];
		for (int i = 0; i < n; i++) {
		    sweet[i] = in.nextInt();
		    a[i] = new Pair(sweet[i], i);
		    map[i] = new TreeMap<>();
		}
		Arrays.sort(a);
		String s = in.next();
		for (int i = 0; i < n; i++) {
		    int x = a[i].y;
		    int y = a[i].x;
		    map[x].put(y, Math.abs(start - x));
		    for (int j = 0; j < n; j++) {
		        if (s.charAt(x) != s.charAt(j) && sweet[x] > sweet[j]) {
		            for (int x1 : map[j].keySet()) {
		                int y1 = map[j].get(x1);
		                int y2 = x1 + y;
		                int z = y1 + Math.abs(x- j);
		                if (map[x].containsKey(y2)) {
		                    map[x].put(y2, Math.min(map[x].get(y2), z));
		                } else {
		                    map[x].put(y2, z);
		                }
		            }
		        }
		    }
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
		    for (int x : map[i].keSet())
		    if (x >= k) {
		        ans = Math.min(ans, map[i].get(x));
		    }}
		}
		if (ans == Integer.MAX_VALUE) {
		    out.print(-1);
		} else {
		    out.print(ans);
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

	}

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


import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class A {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

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

	public class Pair implements Comparable<Pair> {
		int x;
		int y;

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

		public int compareTo(Pair o) {
		    if (x != o.x) {
		        return x - o.x;
		    }
		    return y - o.y;
		}
	}

	public void solve() {
		int n = in.nextInt();
		int start = in.nextInt() - 1;
		int k = in.nextInt();
		Pair[] a = new Pair[n];
		int[] sweet = new int[n];
		TreeMap<Integer, Integer>[] map = new TreeMap[n];
		for (int i = 0; i < n; i++) {
		    sweet[i] = in.nextInt();
		    a[i] = new Pair(sweet[i], i);
		    map[i] = new TreeMap<>();
		}
		Arrays.sort(a);
		String s = in.next();
		for (int i = 0; i < n; i++) {
		    int x = a[i].y;
		    int y = a[i].x;
		    map[x].put(y, Math.abs(start - x));
		    for (int j = 0; j < n; j++) {
		        if (s.charAt(x) != s.charAt(j) && sweet[x] > sweet[j]) {
		            for (int x1 : map[j].keySet()) {
		                int y1 = map[j].get(x1);
		                int y2 = x1 + y;
		                int z = y1 + Math.abs(x- j);
		                if (map[x].containsKey(y2)) {
		                    map[x].put(y2, Math.min(map[x].get(y2), z));
		                } else {
		                    map[x].put(y2, z);
		                }
		            }
		        }
		    }
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
		    for (int x : map[i].keySet())
		    if (x >= k) {
		        ans = Math.min(ans, map[i].get(x));
		    }}
		}
		if (ans == Integer.MAX_VALUE) {
		    out.print(-1);
		} else {
		    out.print(ans);
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

	}

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


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

public class C {

    private static final int oo = Integer.MAX_VALUE / 4;

    private void work() {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        n = sc.nextInt();
        int s = sc.nextInt() - 1;
        k = sc.nextInt();

        r = new int[n];
        for (int i = 0; i < n; i++) r[i] = sc.nextInt();
        char[] c = sc.next().toCharArray();
        sc.close();

        deg = new int[n];
        g = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (c[i] != c[j]) {
                    if (r[i] < r[j]) g[i][deg[i]++] = j;
                    if (r[i] > r[j]) g[j][deg[j]++] = i;
                }
            }
        }

        memo = new int[n][k];
        for(int i = 0; i < n; i++){
            Arrays.fill(memo[i], - 1);
        }

        for(int i = 0; i < n; i++){
            go(i, r[i]);
        }

        int res = oo;
        for(int i = 0; i < n; i++){
            int t = Math.abs(i - s) + memo[i][r[i]];
            if(t < res) res = t;
        }

        System.out.println(res == oo ? -1 : res);
    }

    private int n, k;
    private int[] r, deg;
    private int[][] g, memo;

    private int go(int u, int candies){
        if(candies >= k){
            return 0;
        }
        if(memo[u][candies] >= 0) return memo[u][candies];

        int ret = oo;
        for(int i = 0; i < deg[u]; i++){
            int v = g[u][i];
            int t = Math.abs(u - v) + go(v, candies + r[v]);
            if(t < ret) ret = t;
        }

        return memo[u][candies] = ret;
    }

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


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

public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      // Start writing your solution here. -------------------------------------

      int n      = sc.nextInt();        // read input as integer
      int numberOfWays = getWays(n);

      // Stop writing your solution here. -------------------------------------
      out.close();
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

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

   }
   //--------------------------------------------------------

   private int getWays(int n) {
      if(n%2 == 0)
         return 0;
      return (int)Math.pow(2, n/2);
   }
}


import java.util.Scanner;

import java.math.*;

public class text
{
  public static void main(String[] args)
  {
    double output;
    int polynomial = 0;
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    if (n % 2 != 0)
    {
      output = 0;
    }
    elseXDragSourceContextPeer
    {
      polynomial = n / 2;
      output = Math.pow(2, polynomial);
    }

  int xd = (int) Math.round(output);
  System.out.println(xd);
  }
}


import java.io.*;
import java.util.*;
public class  FillingShapes
{
	public static void main(String[] d)
	{
		HashSet<Integer> hs=new HashSet<>();
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		for (int i=1; i<=sqrt(n*3); i++)
		{
			if(n%i==0)
			{
				hs.add(i);
				hs.add(n/i);
			}
		}
		 if(n%2!=0)
			System.out.println(0);
		else
			System.out.println((hs.size()-2));
	}
}


public class gfg{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n==1||n%2!=0){
            System.out.println("0");
        }else{
            System.out.println(n);
        }
    }

}


import java.util.*;

public class C1_177 {
    static class DisjointSet {

        private int[] id;
        private int[] sz;
        private int count;

        public DisjointSet(int N) {
            count = N;
            id = new int[N];
            sz = new int[N];
            for (int i = 0; i < N; i++) {
                id[i] = i;
                sz[i] = 1;
            }
        }

        public int count() {
            return count;
        }

        public int find(int p) {
            while (p != id[p])
                p = id[p];
            return p;
        }

        public boolean connected(int p, int q) {
            return find(p) == find(q);
        }

        public void union(int p, int q) {
            int i = find(p);
            int j = find(q);
            if (i == j)
                return;

            if (sz[i] < sz[j]) {
                id[i] = j;
                sz[j] += sz[i];
            } else {
                id[j] = i;
                sz[i] += sz[j];
            }
            count--;
        }

        public void reset (int p) {
            for (int i = 0; i < id.length; i++) {
                if (id[i] == p) {
                    sz[i] = 1;
                    id[i] = -1;
                }
            }
        }

        public int maxCount() {
            int c[] = new int[id.length];
            for (int i = 0; i < c.length; i++) {
                if (id[i] >= 0)
                    ++c[id[i]];
            }
            Arrays.sort(c);
            return c[c.length - 1];
        }
    }

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        DisjointSet d = new DisjointSet(n);
        int k = in.nextInt();
        for (int i = 0; i < k; i++) {
            int u = in.nextInt() - 1;
            int v = in.nextInt() - 1;
            d.union(u, v);
        }
        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            int u = in.nextInt() - 1;
            int v = in.nextInt() - 1;
            if (d.connected(u, v)) {
                int parent = d.find(u);
                d.reset(parent);
            }
        }
        System.out.println(d.maxCount());
    }
}


import sun.reflect.generics.tree.Tree;

import java.io.*;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.text.DecimalFormat;
import java.util.*;

public class Newbie {

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

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        long t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

       /* static class descend implements Comparator<pair1> {
            public int compare(pair1 o1, pair1 o2) {
                if (o1.pop != o2.pop)
                    return (int) (o1.pop - o2.pop);
                else
                    return o1.in - o2.in;
            }
        }*/

    static class InputReader {
        public BufferedReader br;
        public StringTokenizer token;

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

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

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

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

        public long nlo() {
            return Long.parseLong(sn());
        }

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

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

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

    static class extra {

        static boolean v[] = new boolean[100001];
        static List<Integer> l = new ArrayList<>();
        static int t;

        static void shuffle(int a[]) {
            for (int i = 0; i < a.length; i++) {
                int t = (int) Math.random() * a.length;
                int x = a[t];
                a[t] = a[i];
                a[i] = x;
            }
        }

        static void shufflel(long a[]) {
            for (int i = 0; i < a.length; i++) {
                int t = (int) Math.random() * a.length;
                long x = a[t];
                a[t] = a[i];
                a[i] = x;
            }
        }

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

        static boolean valid(int i, int j, int r, int c) {
            if (i >= 0 && i < r && j >= 0 && j < c) {
                // System.out.println(i+" /// "+j);
                return true;
            } else {
                //  System.out.println(i+" //f "+j);
                return false;
            }
        }

        static void seive() {
            for (int i = 2; i < 101; i++) {
                if (!v[i]) {
                    t++;
                    l.add(i);
                    for (int j = 2 * i; j < 101; j += i)
                        v[j] = true;
                }
            }
        }

        static int binary(LinkedList<Integer> a, long val, int n) {
            int mid = 0, l = 0, r = n - 1, ans = 0;
            while (l <= r) {
                mid = (l + r) >> 1;
                if (a.get(mid) == val) {
                    r = mid - 1;
                    ans = mid;
                } else if (a.get(mid) > val)
                    r = mid - 1;
                else {
                    l = mid + 1;
                    ans = l;
                }
            }
            return (ans + 1);
        }

        static long fastexpo(long x, long y) {
            long res = 1;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res *= x;
                }
                y = y >> 1;
                x = x * x;
            }
            return res;
        }

        static long lfastexpo(long x, long y, long p) {
            long res = 1;
            x = x % p;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res = (res * x) % p;
                }
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }

           /* void dijsktra(int s, List<pair> l[], int n) {
                PriorityQueue<pair> pq = new PriorityQueue<>(new ascend());
                int dist[] = new int[100005];
                boolean v[] = new boolean[100005];
                for (int i = 1; i <= n; i++)
                    dist[i] = 1000000000;
                dist[s] = 0;
                for (int i = 1; i < n; i++) {
                    if (i == s)
                        pq.add(new pair(s, 0));
                    else
                        pq.add(new pair(i, 1000000000));
                }
                while (!pq.isEmpty()) {
                    pair node = pq.remove();
                    v[node.a] = true;
                    for (int i = 0; i < l[node.a].size(); i++) {
                        int v1 = l[node.a].get(i).a;
                        int w = l[node.a].get(i).b;
                        if (v[v1])
                            continue;
                        if ((dist[node.a] + w) < dist[v1]) {
                            dist[v1] = dist[node.a] + w;
                            pq.add(new pair(v1, dist[v1]));
                        }
                    }
                }
            }*/
    }

    static class pair {
        int a;
        int b;

        public pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }

    static class pair1 {
        pair p;
        int in;

        public pair1(pair a, int n) {
            this.p = a;
            this.in = n;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00");
        extra e = new extra();
        int mod = 1000000007;
        boolean v[] = new boolean[1001];
        void solve() throws IOException {
            int n=sc.ni();
            int p[]=new int[n];
            for(int i=0;i<n;i++)
                p[i]=i;
            HashMap<Integer, Integer> count=new HashMap<>();
            int k=sc.ni();
            while (k-->0)
            {
                int u=sc.ni()-1;
                int v=sc.ni()-1;
                int p1=find(p,u);
                int p2=find(p,v);
                if(p1!=p2)
                    union(p,u,v);
            }
            for(int i=0;i<n;i++)
                find(p,i);
            for(int i=0;i<n;i++)
            {
                count.put(p[i],count.getOrDefault(p[i],0)+1);
            }
            int m=sc.ni();
            //System.out.println(count);
            while (m-->0) {
                int u = sc.ni() - 1;
                int v = sc.ni() - 1;
                int p1 = find(p, u);
                int p2 = find(p, v);
                if (p1 == p2)
                    count.remove(p1);
            }
            int ans=Collections.max(count.values());
            System.out.println(ans);
        }
        int rank[]=new int[100000];
        int find(int p[],int x){
            if(p[x]==x)
                return x;
            p[x]=find(p,p[x]);
            return p[x];
        }
        void union(int p[],int x,int y)
        {
            int p1=find(p,x);
            int p2=find(p,y);
            if(rank[p1]>rank[p2])
            {
                p[p2]=p1;
                rank[p1]=rank[p2]+1;
            }
            else
            {
                p[p1]=p2;
                rank[p2]=Math.max(rank[p1]+1,rank[p2]);
            }
        }
    }
}


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

//4/22/12 1:43 AM
//by Abrackadabra

public class C1 {
    public static void main(String[] args) throws IOException {
        if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
        new C1().run();
        /*new Thread(null, new Runnable() {
            public void run() {
                try {
                    new C1().run();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 24).start();*/
    }

    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
    String taskName = "";

    void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, HashSet<Integer>> friends = new HashMap<Integer, HashSet<Integer>>();
        HashMap<Integer, HashSet<Integer>> enemies = new HashMap<Integer, HashSet<Integer>>();
        HashSet<Integer> badColors = new HashSet<Integer>();
        int[] coloring = new int[n];
        int[] colorCount = new int[n];
        int currentColor = 1;
        int m = nextInt();
        for (int i = 0; i < m; i++) {
            int a = nextInt() - 1, b = nextInt() - 1;
            if (!friends.containsKey(a))
                friends.put(a, new HashSet<Integer>());
            if (!friends.containsKey(b))
                friends.put(b, new HashSet<Integer>());
            friends.get(a).add(b);
            friends.get(b).add(a);
        }
        m = nextInt();
        for (int i = 0; i < m; i++) {
            int a = nextInt() - 1, b = nextInt() - 1;
            if (!enemies.containsKey(a))
                enemies.put(a, new HashSet<Integer>());
            if (!enemies.containsKey(b))
                enemies.put(b, new HashSet<Integer>());
            enemies.get(a).add(b);
            enemies.get(b).add(a);
        }
        for (int i = 0; i < n; i++) {
            if (coloring[i] == 0) {
                int toColor = currentColor++;
                Queue<Integer> queue = new LinkedList<Integer>();
                queue.add(i);
                coloring[i] = toColor;
                colorCount[toColor]++;
                while (!queue.isEmpty()) {
                    int q = queue.poll();
                    if (friends.containsKey(q))
                    for (int t : friends.get(q)) {
                        if (coloring[t] == 0) {
                            coloring[t] = toColor;
                            colorCount[toColor]++;
                            queue.add(t);
                        }
                    }
                    if (enemies.containsKey(q))
                    for (int t : enemies.get(q)) {
                        if (coloring[t] == toColor) {
                            badColors.add(toColor);
                        }
                    }
                }
            }
        }
        int res = 0;
        for (int i = 1; i < currentColor; i++) {
            if (!badColors.contains(i) && colorCount[i] > res)
                res = colorCount[i];
        }
        out.println(res);
    }

    long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
    long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;

    void run() throws IOException {
        init();
        if (debugMode) {
            con.println("Start");
            con.println("Console:");
        }
        solve();
        finishTime = System.nanoTime();
        finishMem = Runtime.getRuntime().totalMemory();
        out.flush();
        if (debugMode) {
            int maxSymbols = 1000;
            BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
            char[] a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println("File input:");
                con.println(a);
                if (a[maxSymbols - 1] != 0) con.println("...");
            }
            tbr = new BufferedReader(new FileReader("output.txt"));
            a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println("File output:");
                con.println(a);
                if (a[maxSymbols - 1] != 0) con.println("...");
            }
            con.println("Execution time: " + (finishTime - startTime) / 1000000000.0 + " sec");
            con.println("Used memory:    " + (finishMem - startMem) + " bytes");
            con.println("Total memory:   " + Runtime.getRuntime().totalMemory() + " bytes");
        }
    }

    boolean tick(double x) {
        if (System.nanoTime() - tempTime > x * 1e9) {
            tempTime = System.nanoTime();
            con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
            con.print("   ");
            return true;
        }
        return false;
    }

    static boolean debugMode = false;
    PrintStream con = System.out;

    void init() throws IOException {
        if (debugMode && IOMode != 3) {
            br = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        } else
            switch (IOMode) {
                case 0:
                    br = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                    break;
                case 1:
                    br = new BufferedReader(new FileReader(taskName + ".in"));
                    out = new PrintWriter(new FileWriter(taskName + ".out"));
                    break;
                case 2:
                    br = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    out = new PrintWriter(new FileWriter("input.txt"));
                    break;
            }
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    boolean hasMoreTokens() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) return false;
            in = new StringTokenizer(line);
        }
        return true;
    }

    String nextString() throws IOException {
        return hasMoreTokens() ? in.nextToken() : null;
    }

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

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

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


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

public class B114 {
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter pw;

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

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

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

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

    static char nextChar() throws IOException {
        return (char) br.read();
    }

    public static void main(String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        run();
        pw.close();
    }

    static ArrayList<Integer> graf[];
    static ArrayList<Integer> grafUn[];
    static TreeMap<String, Integer> treeName = new TreeMap<>();
    static TreeMap<Integer, String> treeInt = new TreeMap<>();
    static TreeSet<Integer> treeUnInt = new TreeSet<>();

    private static void run() {
        int n = nextInt();
        int m = nextInt();
        for (int i = 0; i < n; i++) {
            String s = nextToken();
            treeName.put(s, i);
            treeInt.put(i, s);
        }
        grafUn = new ArrayList[n];
        graf = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            grafUn[i] = new ArrayList<>();
            graf[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                graf[i].add(j);
                graf[j].add(i);
            }
        }
        for (int i = 0; i < m; i++) {
            String s1 = nextToken();
            String s2 = nextToken();
            int x = treeName.get(s1);
            int y = treeName.get(s2);
            grafUn[x].add(y);
            grafUn[y].add(x);
            treeUnInt.add(x);
            treeUnInt.add(y);
        }
        for (int i = 0; i < n; i++) {
            dfs(i, new ArrayList<>(), new TreeSet<>());
        }
        ArrayList<String> anss = new ArrayList<>();
        for (int i = 0; i < ans.size(); i++) {
            anss.add(treeInt.get(ans.get(i)));
        }
        Collections.sort(anss);
        pw.println(anss.size());
        for (int i = 0; i < anss.size(); i++) {
            pw.println(anss.get(i));
        }

    }

    private static <E> void dfs(int v, ArrayList<Integer> es, TreeSet<Integer> no) {
        if (no.contains(v)) return;
        es.add(v);
        for (int i = 0; i < grafUn[v].size(); i++) {
            no.add(grafUn[v].get(i));
        }
        no.add(v);
        for (int i = 0; i < graf[v].size(); i++) {
            dfs(graf[v].get(i), (ArrayList<Integer>) es.clone(), (TreeSet<Integer>) no.clone());
        }
        if (es.size() > ans.size()) {
            ans = es;
        }
    }

    static ArrayList<Integer> ans = new ArrayList<>();

    private static void removeV(int x, int y) {
        for (int j = 0; j < graf[x].size(); j++) {
            if (graf[x].get(j) == y) {
                graf[x].remove(j);
                break;
            }
        }
    }
}


package com.company;

//import java.util.Scanner;

public class RootNumb {
    public static void main (String [] args) {
        Scanner scan = new Scanner(System.in);
        String line = scan.nextLine();
        char charX = line.charAt(0);
        int intY = Character.getNumericValue(line.charAt(1));

        int var = 8;

        if (charX == 'a' || charX == 'h' || intY == 1 || intY == 8) {
            var = 5;
        }

        if ("a1".equals(line) || "h1".equals(line) || "a8".equals(line) || "h8".equals(line)) {
            var = 3;
        }

        System.out.println(var);
    }
}


import java.util.*;
public class Main{
   public static void main(String[] args){
      Scanner in = new Scanner(System.in);
      char s = in.nextChar();
      int t = in.nextInt();
      if((s == a || s == h) && (t==1 || t==8))
      {
         System.out.println(3);
      }
      else if((s == a || s == h) && (t>=2 && t<=7))
      {

            System.out.println(5);

      }
      else if(('s'>'a' && 's'<'h') && (t==1 || t==8))
      {
         System.out.println(5);
      }
      else
       System.out.println(8);
   }
}


import java.util.Scanner;
public class KingMoves{
	public static void main(String[] args){
		Scanner keyboard = new Scanner(System.in);
		String position = keyboard.nextLine();

		char d = position.charAt(0);
		char c = Integer.parseInt(keyboard.next());
		position.charAt(1);

		int moves = 0;

		if ( position.equals("a8") ||position.equals("a1") ||
			 position.equals("h8") ||
			 position.equals("h1") )
			moves = 3;

		else if (d == 'a' || d == 'h' || c == '1' || c == '8')
			moves=5;
		else
			moves=8;

		System.out.println(moves+"");

	}//end of main
}//end of class


import java.util.Scanner;
public class A {
      public static void main(String[]args){
    	  Scanner sc=new Scanner(System.in);
    	  String temp=sc.nextLine();
    	  int p1=temp.charAt(0)-'a'+1;
    	  int p2=temp.charAt(1)-'0;
    	  int ans=8;
    	  if(p1==1||p1==8)ans-=3;
    	  if(p2==1||p2==8)ans-=3;
    	  if(ans==2)ans++;
    	  System.out.println(ans);
      }
}


import java.util.*;

public class DD {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
long t;
t=sc.nextLong();
for(int i=0;i<t;i++)
{
   int n,k,d;
   n=sc.nextInt();
   k=sc.nextInt();
   d=sc.nextInt();
   int a[]=new int[n];
   for(int p=0;p<n;p++)
   {
       a[p]=sc.nextInt();
   }

   long size;
   long fsize=10000;
   for(int z=0;z<=(n-d);z++)
   {
     HashSet<Integer> hs =new HashSet<>();
       for(int u=z;u<(z+d);u++)
       {
           hs.add(a[u]);
       }

       size=hs.size();
       if(size<fsize)
       {
           fsize=size;
       }

   }

   System.out.println(fsize);

    }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class AT2 {
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=scan.nextInt();
        StringBuilder print=new StringBuilder();
        while(t-->0){
            int n=scan.nextInt();
            int k=scan.nextInt();
            int d=scan.nextInt();
            int[] arr=new int[n];
            for (int i = 0; i <n ; i++) {
                arr[i]=scan.nextInt();
            }
            Map<Integer,Integer> m=new HashMap<>();
            for(int i=0;i<d;i++){
                m.putIfAbsent(arr[i],0);
                m.put(arr[i],m.get(arr[i])+1);
            }
            int min=m.keySet().size();
            for(int i=d;i<n;i++){
                int rem=arr[i-d];
                m.put(rem,m.get(rem)-1);
                if(m.get(rem)==0){
                    m.remove(rem);
                }
                m.putIfAbsent(arr[i],0);
                m.put(arr[i],m.get(arr[i])+1);
                min=Math.min(min,m.keySet().size());
            }
            print.append(min+"\n");
        }
        System.out.println(print);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}


import jdk.internal.org.objectweb.asm.tree.IincInsnNode;

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

public class Solver {

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        int t = nextInt();
        for (int i = 0; i < t; i++) {
            int n = nextInt();
            int k = nextInt();
            int d = nextInt();
            int a[] = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = nextInt();
            }
            int min = Integer.MAX_VALUE / 2;
            for (int j = 0; j < n - d + 1; j++) {
                int h[] = Arrays.copyOfRange(a, j, j + d);
                Arrays.sort(h);
                TreeSet<Integer>ts = new TreeSet<>();
                for (int l = 0; l < h.length; l++) {
                    ts.add(h[l]);
                }
                if (ts.size() < min) min = ts.size();
            }
            pw.println(min);
        }
        pw.close();
    }

    static int mod = 1_000_000_009;
    static BufferedReader br;
    static StringTokenizer st = new StringTokenizer("");

    static long nextLong() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return Long.parseLong(st.nextToken());
    }

    static int nextInt() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }

    static double nextDouble() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return Double.parseDouble(st.nextToken());
    }

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

    static PrintWriter pw;
}


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

import Contest596.A.FastReader;

public class B1 {

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader scn = new FastReader();
		int tc = scn.nextInt();
		while (tc-- > 0) {
			int n = scn.nextInt();
			int arr[] = new int[n];
			int k = scn.nextInt();
			int d = scn.nextInt();
			for (int i = 0; i < n; i++) {
				arr[i] = scn.nextInt();
			}
			int cout = Integer.MAX_VALUE;
//			int res[]=new int[n];
//			if (n == d) {
//				int c = 0;
//				int hash[] = new int[k + 1];
//				for (int j = 0; j < n; j++) {
//					hash[arr[j]]++;
////					res[j]
//				}
//				for (int val : hash) {
//					if (val != 0)
//						c++;
//				}
//				cout=Math.min(cout, c);
//			} else {
				for (int i = 0; i <= n - d; i++) {
					int c = 0;
					int hash[] = new int[k + 1];
					for (int j = i; j < i + d && j < n; j++) {
						hash[arr[j]]++;
//					res[j]
					}
					for (int val : hash) {
						if (val != 0)
							c++;
					}
//				res[i]=c;
					cout = Math.min(c, cout);
				}
//			}
			System.out.println(cout);
		}
	}
}


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

public class ques1_507{

	public static void main(String[] args)
    {
		FastReader f = new FastReader();
		PrintWriter wr = new PrintWriter(System.out);
        int n = f.nextInt();
        int a = f.nextInt();
        int b = f.nextInt();
        int[] array = new int[n];
        for(int i=0;i<n;i++)
        {
            array[i] = f.nextInt();
        }
        if(isPalindrome(array))
        {
            int i =0;
            int j = n-1;

            while(j>=0 && i<n)
            {
                if(i<=j)
                {
                    if(array[i] == array[j])
                    {
                        if(array[i]==2 && array[j] == 2)
                        {

                        int min = Math.min(a,b);
                        cost += min;
                        //wr.println(cost);
                        i++;
                        j--;
                        }
                        else
                        {
                        //wr.println("here");
                        i++;
                        j--;
                        }
                    }

                }
                else
                {
                    if(array[i] ==1 && array[j] ==2)
                    {

                        cost += b;
                        i++;
                        j--;
                    }
                    else if(array[i] == 0 && array[j] ==2)
                    {
                        cost += a;
                        //wr.println(cost);
                        i++;
                        j--;
                    }
                    else if(array[j] == 1 && array[i] == 2)
                    {
                        cost += b;
                        i++;
                        j--;
                    }
                    else if(array[j] == 0 && array[i]==2)
                    {
                        //wr.println("HERE");
                        cost += a;
                        i++;
                        j--;
                    }
                }
            }
        }
        else
        {
            if(onesZeros)
            {
                wr.println(0);
            }
            else
            {
                wr.println(-1);
            }

        }

        wr.close();
	}

    static boolean onesZeros(int[] array)
    {
        int ones = 0;
        int zeroes = 0;

        int n = array.length();

        for(int i=0;i<n;i++)
        {
            if(array[i] == 1)
            {
                ones++;
            }
            else if(array[i] == 0)
            {
                zeroes++;
            }
        }

        return (ones==zeroes) ? true:false ;
    }

    static boolean isPalindrome(int[] array,int start,int end)
    {
        int n = end;
        while(start<=n && end>=0)
        {
            if(start<=end)
            {
               if(array[start] == array[end])
                {
                    start++;
                    end--;
                    continue;
                }
                else
                {
                    if(array[start] == 2 || array[end] == 2)
                    {
                        start++;
                        end--;
                        continue;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
        return true;
    }

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
public class name
{
      public static void main(String[]args)throws IOException
      {
            Scanner sc=new Scanner(System.in);
            int n,w,b,a[],i,sum=0;
            n=sc.nextInt();
            w=sc.nextInt();
            b=sc.nextInt();
            a=new int[n];
            sum=0;
            for(i=0;i<n;i++)
            {
                  a[i]=sc.nextInt();
            }
            if((a[0]==1&&a[n-1]==0)||(a[0]==0&&a[n-1]==1))
            System.out.println("-1");
            else if(n%2==0)
            {
                  for(i=0;i<n;i++)
                  {
                        if(a[i]==a[n-i-1)
                        {
                        continue;
                        }
                        else if(a[i]==0)
                        sum+=w;
                        else if(a[i]==1)
                        sum+=b;
                  }
                  System.out.println(sum);
            }
            else if(n%2!=0)
            {
                  for(i=0;i<n;i++)
                  {
                        if((w>b)&&(a[n/2]==2))
                        {
                              a[n/2]=b;
                              sum+=b;
                        }
                        else if((a[n/2]==2)&&(b>w))
                        {
                              a[n/2]=w;
                              sum+=w;
                        }
                        if(a[i]==a[n-i-1)
                        {
                        continue;
                        }
                        else if(a[i]==0)
                        sum+=w;
                        else if(a[i]==1)
                        sum+=b;
                  }
                  System.out.println(sum);
            }

            }


import java.io.*;
import java.util.*;
import java.lang.*;
 public class test{
      static class FastReader{
          BufferedReader br;
          StringTokenizer st;
          public FastReader(){
            br=new BufferedReader(new InputStreamReader(System.in));
           }
        public FastReader(String s)throws FileNotFoundException{
       br=new BufferedReader(new FileReader(new File(s)));
         }
       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;
       }
  }
  public  static void main(String args[]){
    FastReader in=new FastReader();
      int n=in.nextInt();
     int p=in.nextInt();
      int q=in.nextInt();
       int a[]=new int[n];
       for(int i=0;i<n;i++)
         a[i]=in.nextInt();
       int cost=0;
        int min=(p>q)?q:p;
       for(int i=0;i<n/2;i++){
       if((a[i]==2 && a[n-1-i]==0)||(a[i]==0 && a[n-1-i]==2)){
        cost+=p; a[i]=0;a[n-1-i]==0    }
       else if((a[i]==2 && a[n-1-i]==1)||(a[i]==1 && a[n-1-i]==2)){
          cost+=q;a[i]=1;a[n-1-i]=1;
    }
       else if(a[i]==2 && a[n-i-1]==2){
         cost+=min*2;   a[i]=0;a[n-1-i]=0;}
        else if((a[i]==1 && a[n-1-i]==0)||(a[i]==0 && a[n-1-i]==1)){
           cost=-1;
            break;
                }
             }
          if(cost!=-1 && a[n/2]==2)
         cost+=min;
          System.out.print(cost);
    }
 }


import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in) {
            int n = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            // 0 - white, 1 - black, 2 - unknown

            int[] costumes = new int[n];

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

            int can = true;
            int cost = 0;

            for (int i = 0; i < n / 2; i++) {
                if (costumes[i] == costumes[n - i - 1] && costumes[i] == 2) {
                    cost += 2 * Math.min(b, c);
                } else if (costumes[i] != 2 || costumes[n - i - 1] != 2) {
                    can = false;
                    break;
                } else {
                    if (costumes[i] == 1) {
                        cost += c;
                    }
                    if (costumes[i] == 2) {
                        cost += b;
                    }

                    if (costumes[n - i - 1] == 1) {
                        cost += c;
                    }
                    if (costumes[n - i - 1] == 2) {
                        cost += b;
                    }
                }
            }

            if (n % 2 == 1 %% costumes[n / 2 + 1] != 2) {
                cost += Math.min(b, c);
            }

            if (can) {
                System.out.println(cost);
            } else {
                System.out.println(-1);
            }
        }
    }
}


import java.ulil.io.Scanner;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x%2 == 0){
			System.out.println("home");
		} else{
			System.out.println("contest");
		}
	}
}


import com.digwener.arrays.PartialSum;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Anton Berezin on 2/14/2017.
 */
public class TooManyContests {
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {

			int n = Integer.parseInt(reader.readLine());
			String home = reader.readLine();
			List<String> dest = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				String flight = reader.readLine();
				dest.add(flight.substring(5, 8));
			}
			int homes = 0;
			for(int i = 0;i<n;i++) {
				if(dest.get(i).equals(home)) {
					homes++;
				}
			}
			int contests = n - homes;
			if(homes >= contests) {
				System.out.println("home");
			} else {
				System.out.println("contest");
			}

		}

	}
}


public class neverending {
    public static void main(String[] args) {
    	Scanner ab=new Scanner(System.in);
    	int i,n=ab.nextInt();
    	String home=ab.next();
    	String[] list=new String(n);
    	for(i=0;i<n;i++)
    		list[i]=ab.next();
    	if(n%2==0)
    		System.out.println("home");
    	else
    		System.out.println("contest");
    }
}


public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        if(n % 2 == 0) {
            System.out.println("home")
        }
        else{
                        System.out.println("contest")

        }
        return;
    }
}


import java.io.*;
import java.util.*;
public class D83 {
	static int max;
	static int[][] grid;
	static int[] primes;
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		max = Integer.parseInt(st.nextToken());
		primes = new int[3000];
		int c = 1;
		primes[0] = 2;
		for(int i = 3; c < primes.length; i += 2)
			if(prime(i))
				primes[c++] = i;
		grid = new int[10000][3000];
		for(int i = 0; i < grid.length; i++)
			Arrays.fill(grid[i], -1);
		if(!prime(max))	{
			System.out.println(0);
			return;
		}
		System.out.println(compute(b/max, 0) - compute((a-1)/max, 0));
	}
	public static boolean prime(int x)	{
		if(x==1)
			return false;
		if(x<=3)
			return true;
		if(x%2==0 || x%3==0)
			return false;
		for(int d = 5; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		for(int d = 7; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		return true;
	}
	public static int compute(int num, int p)	{
		if(primes[p] >= max || num == 0)
			return num;
		if(num < 10000 && p < 3000 && grid[num][p] != -1)
			return grid[num][p];
		int ret = compute(num,p+1) - compute(num/primes[p],p+1);
		if(num < 10000 && p < 3000)
			grid[num][p] = ret;
		return ret;
	}
}


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

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	while (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

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

    int lp[];
    List<Integer> pr;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);
	int a = nextInt(), b = nextInt(), k = nextInt();
	for(int i = 2; i * i <= k; ++i){
	    if (k % i == 0){
		out.println(0);
		out.close();
		return;
	    }
	}

	if (k > 100){
	    int n = b / k;
	    pr = new ArrayList<Integer>();
	    lp = new int[n + 1];
	    lp[1] = Integer.MAX_VALUE;
	    for(int i = 2; i <= n; ++i){
		if (lp[i] == 0){
		    lp[i] = i;
		    pr.add(i);
		}
		for(int j = 0;j < pr.size() && pr.get(j) <= i && 1L * i * pr.get(j) <= n; ++j){
		    lp[pr.get(j) * i] = pr.get(j);
		}
	    }

	    int res = calc(b, k) - calc(a-1, k);
	    out.println(res);
	}else{
	    pr = new ArrayList<Integer>();
	    for(int i = 2; i < k; ++i){
		if (isPrime(i)){
		    pr.add(i);
		}
	    }

	    int res = calc1(b, k) - calc1(a-1, k);
	    out.println(res);
	}

        out.close();
    }

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

    private int calc(int n, int k){
	int ret = 0;
	for(int i = 1; 1L * i * k <= n; ++i){
	    if (lp[i] >= k){
		++ret;
	    }
	}
	return ret;
    }

    private int calc1(int n, int k){
	int res = n / k;
	int N = pr.size();
	for(int mask = 1; mask < 1 << N; ++mask){
	    int r = n/k;
	    for(int j = 0; j < N; ++j){
	        if ((mask & (1 << j)) > 0){
		    r/=pr.get(j);
		}
	    }
	    if (Integer.bitCount(mask) % 2 == 1){
	        res-=r;
	    }else{
	        res+=r;
	    }
	}

	return res;
    }

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


import java.io.*;
import java.util.*;
public class D83 {
	static int max;
	static int[][] grid;
	static int[] primes;
	public static void main(String[] args) throws IOException	{
		primes = new int[30000];
		int c = 1;
		primes[0] = 2;
		for(int i = 3; c < primes.length; i += 2)
			if(prime(i))
				primes[c++] = i;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		max = Integer.parseInt(st.nextToken());
		grid = new int[1000][30000];
		for(int i = 0; i < grid.length; i++)
			Arrays.fill(grid[i], -1);
		if(!prime(max))	{
			System.out.println(0);
			return;
		}
		System.out.println(compute(b/max, 0) - compute((a-1)/max, 0));
	}
	public static boolean prime(int x)	{
		if(x==1)
			return false;
		if(x<=3)
			return true;
		if(x%2==0 || x%3==0)
			return false;
		for(int d = 5; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		for(int d = 7; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		return true;
	}
	public static int compute(int num, int p)	{
		if(primes[p] >= max || num <= 1)
			return num;
		if(num < 1000 && p < 30000 && grid[num][p] != -1)
			return grid[num][p];
		int ret = compute(num,p+1) - compute(num/primes[p],p+1);
		if(num < 1000 && p < 30000)
			grid[num][p] = ret;
		return ret;
	}
}


import net.llinux.Utils;

import java.io.*;

/**
 * Codeforces Beta Round #72 (Div. 1 Only), D
 * @author Roman Kosenko <madkite@gmail.com>
 */
public class C083D_Numbers {
	public static void main(String... args) throws IOException {
		long time = 0;
		if(args.length != 0) {
			System.setIn(new FileInputStream(args[0]));
			time = System.currentTimeMillis();
			primes = null;
		} else if(!Boolean.parseBoolean(System.getProperty("ONLINE_JUDGE"))) {
			main("in/C083D.1.txt");
			main("in/C083D.2.txt");
			main("in/C083D.3.txt");
			//main("input.txt");
			return;
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] ss = br.readLine().split(" ");
		int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), k = Integer.parseInt(ss[2]), result = !Utils.isPrime(k) ? 0 : solve(a, b, k);
		System.out.println(result);

		//if(time != 0)
		//	System.out.println(System.currentTimeMillis() - time);
	}
	private static int primes[];
	private static int solve(int a, int b, int k) {
		final int start = (a - 1) / k + 1, end = b / k;
		if(end < start)
			return 0;
		if(end == start)
			return 1;
		if(primes == null)
			primes = Utils.primes(k - 1, 0);
		int result = end - start + 1;
		for(int i = 0; i < primes.length && primes[i] < k; i++)
			result -= solve(start, end, primes[i]);
		return result;
	}
}


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

public class C {
  private static final BigInteger MOD = new BigInteger("1000000007");

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

    StringTokenizer st = new StringTokenizer(in.readLine());
    int x = Integer.parseInt(st.nextToken());
    BigInteger n = new BigInteger(st.nextToken());

    System.out.println(solve(x, n));

    in.close();
  }

  private static BigInteger solve(int x, BigInteger n) {
    List<Integer> primes = findPrimes(x);

    BigInteger result = BigInteger.ONE;

    for (int p : primes) {
      BigInteger prime = new BigInteger(Integer.toString(p));
      BigInteger numPrime = BigInteger.ZERO;

      for (BigInteger i = prime; i.compareTo(n) <= 0; i = i.multiply(prime)) {
        numPrime = numPrime.add(n.divide(i));
      }

      BigInteger power = modPower(prime, numPrime);

      result = result.multiply(power).mod(MOD);
    }

    return result.mod(MOD);
  }

  private static List<Integer> findPrimes(int x) {
    List<Integer> primes = new ArrayList<>();

    int i = 2;
    while (x > 1) {
      if (x % i == 0) {
        primes.add(i);

        while (x % i == 0) {
          x /= i;
        }
      }

      i++;
    }

    return primes;
  }

  private static BigInteger modPower(BigInteger prime, BigInteger numPrime) {
    if (numPrime == BigInteger.ZERO) {
      return BigInteger.ONE;
    }

    if (numPrime.mod(BigInteger.TWO) == BigInteger.ZERO) {
      BigInteger result = modPower(prime, numPrime.divide(BigInteger.TWO)).mod(MOD);

      return result.multiply(result).mod(MOD);
    }

    return modPower(prime, numPrime.subtract(BigInteger.ONE))
            .mod(MOD)
            .multiply(prime)
            .mod(MOD);
  }
}


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

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

    static class CPrimesAndMultiplication {
        int MODULO = (int) 1e9 + 7;

        public void solve(int testNumber, InputReader in, OutputWriter out) {

            long x = in.nextLong();
            long n = in.nextLong();

            long ans = 1;

            List<Main.LongIntPair> primeFactors = Main.factorize(x);
            for (Main.LongIntPair primeFactor : primeFactors) {
                long pow = 0;
                long p = primeFactor.first;
                long prime = primeFactor.first;
                for (int i = 0; i <= 63; i++) {
                    long d = n / p;
                    if (d <= 0) break;
                    pow += d;

                    long overflowCheck = p;
                    p *= prime;//check for overflow
                    if (p / overflowCheck != prime) {
                        break;
                    }
                }

                ans *= Main.power_mod(prime, pow, MODULO);
                ans %= MODULO;

            }

            out.println(ans);
        }

    }

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

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

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

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

        public String nextToken() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

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

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

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public OutputWriter println(long i) {
            writer.println(i);
            return this;
        }

    }

    static final class Main {
        public static List<Main.LongIntPair> factorize(long number) {
            List<Main.LongIntPair> result = new ArrayList<>();
            for (long i = 2; i * i <= number; i++) {
                if (number % i == 0) {
                    int power = 0;
                    do {
                        power++;
                        number /= i;
                    } while (number % i == 0);
                    result.add(Main.LongIntPair.makePair(i, power));
                }
            }
            if (number != 1) {
                result.add(Main.LongIntPair.makePair(number, 1));
            }
            return result;
        }

        static long power_mod(long a, long pow, long mod) {
            long res = 1;
            a = a % mod;
            while (pow > 0) {
                if ((pow & 1) == 1)
                    res = (res * a) % mod;
                pow = pow >> 1;
                a = (a * a) % mod;
            }
            return res;
        }

        public static class LongIntPair implements Comparable<Main.LongIntPair> {
            public final long first;
            public final int second;

            public static Main.LongIntPair makePair(long first, int second) {
                return new Main.LongIntPair(first, second);
            }

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

            public boolean equals(Object o) {
                if (this == o) {
                    return true;
                }
                if (o == null || getClass() != o.getClass()) {
                    return false;
                }

                Main.LongIntPair pair = (Main.LongIntPair) o;

                return first == pair.first && second == pair.second;
            }

            public int hashCode() {
                int result = Long.hashCode(first);
                result = 31 * result + Integer.hashCode(second);
                return result;
            }

            public String toString() {
                return "(" + first + "," + second + ")";
            }

            public int compareTo(Main.LongIntPair o) {
                int value = Long.compare(first, o.first);
                if (value != 0) {
                    return value;
                }
                return Integer.compare(second, o.second);
            }

        }

    }
}