import java.util.Scanner;

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

		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), i, j;
		String t = in.next(), s = "";
		in.close();

		for (i = 2; i <= n; i++)
			if (n % i == 0) {
				for (j = i - 1; j >= 0; j--)
					s += t.charAt(j);

				s += t.substring(i);
				t = s;
				s = "";
			}
		System.out.println(t);
	}
}


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

//solution classes here

public class Code {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static long mod = 998244353;
    static long MOD = (long)1e9+7;
    //static ArrayList<Integer> list[] = new ArrayList[(int)1e6+1];
    //static int color[] = new int[(int)1e6+1];
    //static int visit[] = new int[(int)1e5+1];
    //static Deque<Integer> q = new ArrayDeque<>();
    public static void main(String[] args) throws IOException {
        int n = sc.nextInt();
        if(n%2==0) {
            out.println("white");
            out.print("1 2");
        }
        else {
            out.print("black");
        }

        out.flush();
        out.close();
    }
    //solution functions here

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

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

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

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

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class CodeforcesC implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

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

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

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

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

    long timeBegin, timeEnd;

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

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

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

    int[] readIntArray(int n) throws IOException {
        int[] array = new int[n];
        for (int i = 0; i < n; i++)
            array[i] = readInt();
        return array;
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws IOException {

        int l = readInt();
        int r = readInt();

        int n = 9;
        int[] ten = new int[n + 1];

        ten[0] = 1;

        for (int i = 1; i <= n; i++)
            ten[i] = 10 * ten[i - 1];

        long answer = 0;

        List<Long> luckyNumbers = new ArrayList<Long>();

        for (int length = 1; length <= n; length++) {
            for (int cur = 0; cur < (1 << length); cur++) {
                int value = 0;
                for (int j = 0; j < length; j++) {
                    if (((1 << j) & cur) == (1 << j))
                        value += ten[j] * 7;
                    else
                        value += ten[j] * 4;
                }
                //out.println(value);
                luckyNumbers.add(1l * value);
            }
        }

        luckyNumbers.add(4444444444l);

        long lastNumber = l;

        for (long luckyNumber : luckyNumbers) {
            if (luckyNumber > r) {
                answer += 1l * (r - lastNumber + 1) * luckyNumber;
                break;
            }
            if (luckyNumber >= l) {
                answer += 1l * (luckyNumber - lastNumber + 1) * luckyNumber;
                lastNumber = luckyNumber + 1;
            }
        }

        out.println(answer);
    }
}


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

public class TaskB {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new TaskB().solve(in, out);
		in.close();
		out.close();
	}

	private void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		int m = in.nextInt();
		if (m < n) {
			n += m;
			m = n - m;
			n -= m;
		}
		int g = 0, f = 0;
		f += n;
		g += m - 1;
		out.println(g + " " + f);
	}

}


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

public class eduA {
public static void main(String[] args) throws IOException {
	BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	String [] s = bf.readLine().split(" ");
	String [] s1 = bf.readLine().split(" ") ;
	int n [] = new int [4] ;
	n[0] = Integer.parseInt(s[0]) ;
	n[1] = Integer.parseInt(s1[0]) ;
	n[2] = Integer.parseInt(s[1]);
	n[3] = Integer.parseInt(s1[1]) ;
	int n1 = Math.abs(n[1]- n[0]) ;

	int n2 = Math.abs(n[3]- n[2]);

			int answer = Math.max(n1, n2) ;
			System.out.println(answer);
}
}


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

public class A {
    FScanner in = new FScanner();
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);

    void run() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            a[i] = x;
        }
        out.print(a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 == 1 ?
                "Yes" :
                "No");
        out.close();
    }

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

    static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

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

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

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


import java.util.Scanner;

public class MyClass {

    static int c, d, n, m, k, commonParty, must;

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

        c = sc.nextInt();
        d = sc.nextInt();
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        commonParty = n * m;
        must = commonParty - k;

        if (must > 0) {

            int algC = algC();
            int algD = algD();

            int algJoint = algC - c;
            int partyCMinusRound = (algJoint / c) * n;

            int i = (must - partyCMinusRound);
            while (i > 0) {
                i -= 1;
                algJoint += d;
            }

            System.out.println(min(algC, algD, algJoint));
        } else {
            System.out.println(0);
        }

    }

    public static int algC() {
        int tempCommonParty = must;
        int sumTask = 0;
        while (tempCommonParty > 0) {
            tempCommonParty -= n;
            sumTask += c;
        }
        return sumTask;
    }

    public static int algD() {
        int tempCommonParty = must;
        int sumTask = 0;
        while (tempCommonParty > 0) {
            tempCommonParty -= 1;
            sumTask += d;
        }
        return sumTask;
    }

    public static int algFull() {
        //int tempCommonParty = must;
        int algC = algC();
        int algD = algD();

        int sumTask = algC - n;
        int partyCMinusRound = algC * (n - 1);

        int i = (must - partyCMinusRound);
        while (i > 0) {
            i -= 1;
            sumTask += d;
        }

        return min(algC, algD, sumTask);
    }

    public static int min(int... numbers) {
        int minNumber = Integer.MAX_VALUE;

        for (int number : numbers) {
            minNumber = (number < minNumber) ? number : minNumber;
        }

        return minNumber;
    }
}


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

import java.util.Scanner;

/**
 *
 * @author atheeralharbi
 */
public class JavaApplication29 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

          Scanner read = new Scanner(System.in);
          String s3 = read.next();
          String s4 = read.next();

          s3 = s3.toUpperCase();
		s4 = s4.toUpperCase();

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

             if ((s3.charAt(i) == s4.charAt(i)) && (i == s3.length()-1) ){
                 System.out.println(0);
             break;}

              if (s3.charAt(i) > s4.charAt(i)){

              System.out.println(1);
              break;
              }
                 if (s3.charAt(i) < s4.charAt(i)){

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

          }
    }

}


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

public class Pascal {

    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader br;
    static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int n = nextInt();
        int k = nextInt();
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < k; i++) {
            if (n % i == 0) {
                int x = (n / (i % k)) * k + i;
                if(x < min) min = x;
            }
        }
        out.print(min);
        out.close();
    }

    static int nextInt() throws IOException {
        if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    static long nextLong() throws IOException {
        if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }

    static String next() throws IOException {
        if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}


import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[][][] cs = new char[20][8][8];
        for(int i = 0; i < 8; i++) {
            cs[0][i] = sc.next().toCharArray();
        }

        for(int i = 0; i < 19; i++) {
            for(int y = 0; y < 8; y++)
                for(int x = 0; x < 8; x++)
                    if(cs[i][y][x] == 'M')
                        for(int dy = -1; dy <= 1; dy++)
                            for(int dx = -1; dx <= 1; dx++) {
                                final int xx = x+dx;
                                final int yy = y+dy;
                                if(0 <= xx && xx < 8 && 0 <= yy && yy < 8 && cs[i][yy][xx] != 'S')
                                    cs[i+1][yy][xx] = 'M';
                            }

            for(int y = 6; y >= 0; y--)
                for(int x = 0; x < 8; x++)
                    if(cs[i][y][x] == 'S')
                        cs[i+1][y+1][x] = 'S';
        }

        String res = "LOSE";
        for(int y = 0; y < 8; y++)
            for(int x = 0; x < 8; x++)
                if(cs[19][y][x] == 'M')
                    res = "WIN";
        System.out.println(res);
    }
}


import java.util.Scanner;

/**
 *
 * @author Annie
 */
public class Sticks {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);
        int a[] = new int[6];
        int y=0,no=0;
        for(int i=0;i<6;i++){
        a[i]=s.nextInt();
        }

        int b[] = new int[10];

        for(int i=0;i<6;i++){
        int x = a[i];
          b[x]++;
        }

        for(int i=1;i<10;i++){
        if(b[i]==4){

        for(int j=1;j<10;j++){
        if(b[j]==2){
            y++;
        }
        else{
         int x=1;
        }
        }

        }//if closed

        else if(b[i]>4){
        if(b[i]==6){
        y++;
        }
        else{
        int x=1;
        }
        }

        else{
        no++;
        }

        }//for closed

        if(no==9){

        System.out.println("Alien");
                }
        else{
        if(y==1){
        System.out.println("Elephant");
        }
        else{
        System.out.println("Bear");
        }

        }

    }

}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long res = (n / 2) + (n / 3) - (n / 6) + (n / 42)
                  +(n / 5) + (n / 7) + (n/ 30) + (n / 70) + (n / 105)
                  -(n / 10) - (n / 15) - (n / 14) - (n / 21) - (n / 35) - (n / 210);
        System.out.println(n - res);
    }
}


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

public class Luckysubstring {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        int count4 = 0;
        int count7 = 0;
        in.close();
        if (input.contains("4") || input.contains("7")) {
            for (int i = 0; i < input.length(); i++) {
                if (input.charAt(i) == '4') {
                    count4++;
                } else if (input.charAt(i) == '7') {
                    count7++;
                }
            }
            if (count4 >= count7) {
                System.out.println(4);
            } else {
                System.out.println(7);
            }
        } else {
            System.out.println(-1);
        }

    }
}


import java.util.*;

public class A {
public static void main(String args[]) {
	Scanner in = new Scanner(System.in);
	int n=in.nextInt(),x=in.nextInt(),y=in.nextInt();
	double ans = y*n/100.0 - x;
	if (ans<0) ans =0;
	if (ans==(long)ans) System.out.println((int)ans); else System.out.println((long)ans+1);

 }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Test {
    InputStream is;
    PrintWriter out;
    String INPUT = "";
    long[] F;

    void solve()
    {
        F = new long[17];
        F[0] = 1;
        for(int i = 1;i <= 16;i++)F[i] = F[i-1] * i;

        long K = nl();
        int t = ni();
        K--;
        gouter:
        for(int len = 1;;len++){
            long ret = 0;
            int[] rem = new int[16];
            Arrays.fill(rem, t);
            outer:
            for(int i = 0;i < len;i++){
                for(int j = i == 0 ? 1 : 0;j < 16;j++){
                    rem[j]--;
                    long count = count(rem, len-1-i);
                    if(K < count){
                        ret = ret * 16 + j;
                        continue outer;
                    }else{
                        K -= count;
                    }
                    rem[j]++;
                }
                continue gouter;
            }
            out.println(Long.toHexString(ret));
            return;
        }
    }

    long count(int[] rem, int len)
    {
        long[] dp = new long[len+1];
        dp[0] = F[len];
        for(int x : rem){
            if(x < 0)return 0;
            if(x == 0)continue;
            for(int i = len;i >= 0;i--){
                for (int j = 1; j <= x; j++) {
                    if ((i - j) < 0) break;
                    dp[i] += dp[i - j] / F[j];
                }
            }
        }
        return dp[len];
    }

    void run() throws Exception
    {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis()-s+"ms");
    }

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

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

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

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = true;//System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner (System.in);
		int N;
		while(input.hasNext())
		{
			N = input.nextInt();
			int ans = (N/7)*2;
			int Mod = N%7;
			if(Mod == 0)
				System.out.printf("%d %d\n",ans, ans);
			else if(Mod == 1)
				System.out.printf("%d %d\n",ans, ans+1);
			else if(Mod >= 2 && Mod <= 5)
				System.out.printf("%d %d\n",ans, ans+2);
			else
				System.out.printf("%d %d\n",ans+1, ans+2);
		}
	}
}


import java.util.Scanner;

public class Third {

       public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        int n = input.nextInt();
        int o = n+1;
        int array [] = new int [n];
        for (int i = 0; i<n; i++){
        array[i]=(i+1);
        }
        int m = input.nextInt();
        input.nextLine();
        for (int j = 0; j < m; j++){
           int r = input.nextInt();
              for (int l = r-1; l<o-1; l++){
              array [l] = r;
              }
           if (  r < o)
           o = r;
        }
            for (int i=0; i< n; i++)
            System.out.print (array[i]+" ");

    }
}


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

public class E implements Runnable{
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	int MAX = 511, MOD = 998244353, INV = 499122177;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int k = fs.nextInt();
		if(n == 1) {
			System.out.println(0);
			return;
		}

		int[][] dp = new int[MAX][MAX];
		dp[1][1] = 2;
		for(int pos = 0; pos < n; pos++) {
			int[][] ndp = new int[MAX][MAX];

			for(int i = 1; i <= Math.min(k, n); i++) {
				for(int j = 1; j <= Math.min(k, n); j++) {
					int nm = Math.max(i, j+1);
					ndp[nm][j+1] = add(ndp[nm][j+1], dp[i][j]);
					ndp[i][1] = add(ndp[i][1], dp[i][j]);

				}
			}
			if(pos != n-1)
				dp = ndp;
		}

		int[] nums = new int[MAX];
		int[] div2 = new int[MAX];
		for(int i = 1; i <= Math.min(n, k); i++) {
			for(int j = 1; j <= Math.min(n, k); j++) {
				nums[i] = add(nums[i], dp[i][j]);
			}
		}
		for(int i = 1; i <= n; i++) div2[i] = mult(nums[i], INV);

		int res = 0;
		for(int i = 1; i <= Math.min(n, k); i++) {
			for(int j = 1; j <= Math.min(n, k); j++) {
				if(i * j < k) {
					res = add(res, mult(2, mult(div2[i], div2[j])));
				}
			}
		}

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

	int mult(int a, int b) {
		long aa = a;
		if(aa >= MOD) aa -= MOD;
		if(b >= MOD) b -= MOD;
		aa *= b;
		if(aa >= MOD) aa %= MOD;
		return (int)aa;
	}

	int add(int a, int b) {
		if(a >= MOD) a -= MOD;
		if(b >= MOD) b -= MOD;
		a += b;
		if(a >= MOD) a-= MOD;
		return a;
	}

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 50; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


import java.util.*;

public class a {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
in.next();
String str = in.next();
if(str.contains("CC")||str.contains("YY")||str.contains("MM")){
System.out.println("No");
return;
}

if(str.startsWith("?")||str.endsWith("?")||str.contains("??")||str.contains("C?C")||str.contains("Y?Y")||str.contains("M?M"))
System.out.println("Yes");
else
System.out.println("No");

}
}


import java.io.*;
import java.util.*;
import java.math.*;
public
class TaskA{
    //static variable
    static final int mod = (int) 1e9 + 7;
    static final double eps = 1e-6;
    static final double pi = Math.PI;
    static final long inf = Long.MAX_VALUE / 2;

    BufferedReader br;
    void main1() throws IOException {
        br=new BufferedReader(new InputStreamReader(System.in));
        int t=ii();
        int[] aa=new int[t];
        for (int i = 0; i <t ; i++) {
            aa[i]=ii();
        }
        int flag=0;
        int a=1,b=2;
        for (int i = 0; i <t ; i++) {
            if(aa[i]==a)
                b=6-(a+b);
            else if(aa[i]==b)
                a=6-(a+b);
            else {
                flag = 1;
                break;
            }

        }

        if(flag==1)
            System.out.println("NO");
        else
            System.out.println("YES");

    }

    //Main Method............................................................................................................
    public static void main(String[] args) throws IOException {new TaskA().main1();}
    //.......................................................................................................................

    //static class
    static class Pair{
        int key,value;
        Pair(int key,int value){
            this.key=key;
            this.value=value;
        }
        int Key(){
            return key;
        }
        int Value(){
            return value;
        }
    }
    //input method
    int[] iint() throws IOException{
        String line[]=br.readLine().split(" ");
        int[] a=new int[line.length];
        for (int i=0;i<line.length ;i++ ) {
            a[i]=Integer.parseInt(line[i]);
        }
        return a;
    }
    long[] ilong() throws IOException{
        String line[]=br.readLine().split(" ");
        long[] a=new long[line.length];
        for (int i=0;i<line.length ;i++ ) {
            a[i]=Long.parseLong(line[i]);
        }
        return a;
    }
    double[] idouble() throws IOException{
        String line[]=br.readLine().split(" ");
        double[] a=new double[line.length];
        for (int i=0;i<line.length ;i++ ) {
            a[i]=Long.parseLong(line[i]);
        }
        return a;
    }
    long li() throws IOException{

        return Long.parseLong(br.readLine());
    }
    int ii() throws IOException{

        return Integer.parseInt(br.readLine());
    }
    double di() throws IOException{
        return Double.parseDouble(br.readLine());
    }
    char ci() throws IOException{
        return (char)br.read();
    }
    String si() throws IOException{
        return br.readLine();
    }
    String[] isa() throws IOException{
        String at =si();
        return at.split(" ");
    }

    double[][] idm(int n, int m) throws IOException{
        double a[][] = new double[n][m];
        for (int i = 0; i < n; i++) {
            double[] temp=idouble();
            for (int j = 0; j < m; j++) a[i][j] = temp[j];
        }
        return a;
    }

    int[][] iim(int n, int m) throws IOException{
        int a[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
            int[] temp=iint();
            for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    long[][] ilm(int n, int m) throws IOException{
        long a[][] = new long[n][m];
        for (int i = 0; i < n; i++) {
            long[] temp=ilong();
            for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }

}


import java.util.*;

public class Sleep
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter first time");
        String s = sc.next();
        // System.out.println("Enter second time");
        String t = sc.next();

        int shours = Integer.valueOf(s.substring(0,2));
        int thours = Integer.valueOf(t.substring(0,2));

        int smins = Integer.valueOf(s.substring(3));
        int tmins = Integer.valueOf(t.substring(3));

        int answerhours = shours - thours;
        if (answerhours < 0)
            answerhours += 24;

        int answermins = smins - tmins;
        if (answermins < 0)
        {
            answermins += 60;
            answerhours--;
            if (answerhours < 0)
                answerhours = 23;
        }

        String stringhours = Integer.toString(answerhours);
        String stringmins = Integer.toString(answermins);

        if (stringhours.length() == 1)
        {
            stringhours = "0"+stringhours;
        }
        if (stringmins.length() == 1)
        {
            stringmins = "0" + stringmins;
        }
        System.out.println(stringhours + ":" + stringmins);
    }
}


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

public class A151 {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), l = s.nextInt() * s.nextInt(), d = s.nextInt() * s.nextInt(), p = s.nextInt(),
				nl = n * s.nextInt(), nd = n, np = n * s.nextInt();
		int[] c = new int[3];
		c[0] = l / nl;
		c[1] = d / nd;
		c[2] = p / np;
		Arrays.sort(c);
		System.out.println(c[0]);
	}

}


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

public class Edu43B {
    int n, m;
    long k;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextLong();
        solve();
    }

    void solve() {
        long ansX = 0;
        long ansY = 0;
        if (k < n) {
            ansX = (int)k + 1;
            ansY = 1;
        } else {
            k -= n;
            long count = k / (m - 1);
            ansX = n - count;
            if (count % 2 == 0) {
                ansY = 2 + (int)(k % (m - 1));
            } else {
                ansY = m - (int)(k % (m - 1));
            }
            /*
            while (true) {
                if (k <= m - 2) {
                    ansX = n - count;
                    if (count % 2 == 0) {
                        ansY = 2 + (int)k;
                    } else {
                        ansY = m - (int)k;
                    }
                    break;
                }
                k -= m - 2;
                if (k == 1) {
                    ansX = n - count - 1;
                    if (count % 2 == 0) {
                        ansY = m;
                    } else {
                        ansY = 2;
                    }
                }
                k--;
                count++;
            }
            */
        }
        System.out.printf("%d %d\n", ansX, ansY);
    }

    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.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author da_201612051
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    FastIO in = new FastIO(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA1 solver = new TaskA1();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA1 {

    public void solve(int testNumber, FastIO in, PrintWriter out) {
      int n = in.nextInt();
      int k = in.nextInt();
      int[] query = in.nextIntArray(n);
      int cost = 0;
      Set<Integer> availableBooks = new HashSet<>(k);
      int[] access = new int[81];
      int removable = -1;
      for (int i = 0; i < n; i++) {
        access[query[i]]++;
      }
      for (int i = 0; i < n; i++) {
        int currentBook = query[i];
        boolean doesNotContain = !availableBooks.contains(currentBook);
        if (doesNotContain) {
          cost++;
        }
        if (removable != -1) {
          availableBooks.remove(removable);
          removable = -1;
        } else if (availableBooks.size() == k && doesNotContain) {
          int removableBook = -1;
          int count = k;
          Set<Integer> known = new HashSet<>();
          for (int j = i + 1; j < n && count > 0; j++) {
            if (availableBooks.contains(query[j]) && !known.contains(query[j])) {
              count--;
              known.add(query[j]);
              removableBook = query[j];
            }
          }
          if (removableBook != -1) {
            availableBooks.remove(removableBook);
          } else {
            availableBooks.remove(availableBooks.iterator().next());
          }
        }
        availableBooks.add(currentBook);
        if (--access[currentBook] == 0) {
          removable = currentBook;
        }
      }
      out.println(cost);
    }

  }

  static class FastIO {

    final private int BUFFER_SIZE = 1 << 16;
    private InputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public FastIO() {
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public FastIO(InputStream inputStream) {
      this();
      din = new DataInputStream(inputStream);
    }

    public FastIO(String file_name) {
      try {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }

    public int nextInt() {
      int ret = 0;
      try {
        byte c = read();
        while (c <= ' ') {
          c = read();
        }
        boolean neg = (c == '-');
        if (neg) {
          c = read();
        }
        do {
          ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');

        if (neg) {
          return -ret;
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return ret;
    }

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

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

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

  }
}


import java.util.*;
public class gg{
	static int special(int u, int k,int []a){
		if(a[u]==1)
			return k-u;
		if(a[k]==1000)
			return k-u;
		else
			return k-u-1;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int i,max=0;
		for(i=0;i<n;i++)
			a[i]=sc.nextInt();
		Arrays.sort(a);
		int c=0,k=0,u=0,l=0;
		boolean g=true;
		for(i=0;i<n-1;i++){
			if(a[i+1]-a[i]==1&&g==true)
			{
				u=i;
				g=false;
				//System.out.println(u);
			}
			if(a[i+1]-a[i]!=1&&g==false)
			{
				k=i;
				g=true;
				 l=special(u,k,a);
				if(l>max)
					max=l;
				//c=c+l;
				//if(l!=0)
				//break;
			}
		}
		if(!g)
		{
			k=n-1;
			l=special(u,k,a);
			if(l>max)
			max=l;
		}
		//System.out.println(u+" "+k);
		System.out.println(max);
	}
}


import java.util.* ;
public class contes
{
   public static void main(String ar[])
   {
      Scanner sc =  new Scanner(System.in) ;
      int n = sc.nextInt() ;
      int m = sc.nextInt() ;
      int max = 0 ;
      int sum = 0 ;
      for(int i = 0 ; i <n ; i++)
         {
            int k = sc.nextInt() ;
            max = Math.max(max, k) ;
            sum += k ;
         }
      int ans2 = m + max ;
      int ans1 = Math.max(max, (sum + n + m - 1) / (n)) ;
      System.out.println(ans1+" "+ans2) ;
   }
}


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

public class solution {
    public static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

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

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

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

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[101];

        for (int i = 0; i < m; i++) {
            int b = in.nextInt();
            a[b]++;
        }
       for(int i=m;i>=1;i--){
           int k = 0;
           for(int j = 1;j<101;j++){
                k+=a[j]/i;
           }
           if(k>=n){
               System.out.println(i);
               return;
           }
       }
        System.out.println(0);
    }

    static class sort implements Comparator<ArrayList<Integer>> {

        @Override
        public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
            int c = o1.get(0).compareTo(o2.get(0));
            return c;
        }

    }
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class b {

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

		char[] arr=s.next().toCharArray();
		char[] brr=s.next().toCharArray();
		int ans=0;
		int n=arr.length;
		for(int i=0;i<n;i++) {
			for(int j=i;j<n;j++) {
				int count=0;
				for(int k=0;k<n;k++) {

					if(k<i||k>j) {
						if(count<brr.length) {
					  	if(arr[k]==brr[count]) {
					  		count++;
					  	}
						}else {
							break;
						}
					}
				}

				if(count==brr.length) {
					if(ans<j-i+1) {
						ans=j-i+1;
					}
				}
			}
		}

		System.out.println(ans);

	}
}


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

public class Main {
	public static void main(String args[]) throws FileNotFoundException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new Solver().solve(in, out);
		out.close();
	}
}

class Fibonacci{
	private long mod;
	private Map<Long, Long> calculatedNumbers;

	public Fibonacci(long mod){
		calculatedNumbers = new TreeMap<>();
		calculatedNumbers.put(0l, 1l);
		calculatedNumbers.put(1l, 1l);
		this.mod = mod;
	}

	public long fib(long n){
		if(calculatedNumbers.containsKey(n)) return calculatedNumbers.get(n);

		long k = n/2, res;
		if(n%2 == 0){
			res = (fib(k)*fib(k)+fib(k-1)*fib(k-1))%mod;
		}else{
			res = (fib(k)*fib(k+1)+fib(k-1)*fib(k))%mod;
		}
		calculatedNumbers.put(n, res);
		return res;
	}
}

class Exponentation{
	//a^b mod m
	public static long calc(long a, long b, long m){
		if(b == 0) return 1;
		if(b == 1) return a;
		if(b%2 == 0) return calc(a*a%m, b/2, m);
		else return a*calc((a*a%m), (b-1)/2, m)%m;
	}
}

class Solver{
	long n, k, l, MOD;

	void read(InputReader in){
		n = in.nextLong();
		k = in.nextLong();
		l = in.nextLong();
		MOD = in.nextLong();
	}

	public void solve(InputReader in, PrintWriter out){
		read(in);
		if(l != 64 && (1l << l)-1 < k){
			out.println(0);
			return;
		}

		long zeroPos = new Fibonacci(MOD).fib(n+1);
		long onePos = Exponentation.calc(2, n, MOD)-zeroPos;
		while(onePos < 0) onePos += MOD;

		long res = 1;
		for(int i=0; i<l; i++){
			if((k & (1l << i)) != 0) res *= onePos;
			else res *= zeroPos;
			res %= MOD;
		}
		out.println(res%MOD);
	}
}

class InputReader {
	public BufferedReader reader;
	String currentLine[];
	int token;

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

	public String next(){
		while (currentLine == null || token >= currentLine.length) {
			try {
				currentLine = reader.readLine().split("\\s+");
				token = 0;
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return currentLine[token++];
	}

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

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


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

// PROBLEM : Can teleport between cells corresponding to the same string
public class B {
    static int n;
    static char[][] G;
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        G = new char[n][n];
        F = new HashMap<Long, Integer>();
        for(int r=0; r<n; r++) {
            G[r] = in.next().toCharArray();
        }
        int ans = ch_to_val(G[0][0],true)-f(0,new boolean[]{true},false);
        if(ans > 0) System.out.println("FIRST");
        if(ans < 0) System.out.println("SECOND");
        if(ans == 0) System.out.println("DRAW");
    }

    static int ch_to_val(char ch, boolean first) {
        if(ch=='a') return first ? 1 : -1;
        if(ch=='b') return first ? -1 : 1;
        return 0;
    }

    static long hash(int sum, boolean[] R) {
        long hash = sum;
        for(int i=0; i<R.length; i++)
            hash = hash*2 + (R[i] ? 1 : 0);
        return hash;
    }

    // Returns max score for person to play; given square has already been claimed
    static HashMap<Long,Integer> F;
    static int f(int sum, boolean[] R, boolean first) {
        long key = hash(sum, R);
        if(F.containsKey(key)) return F.get(key);
        if(sum == 2*(n-1)) return 0;

        int ans = -1000;
        int ns = sum+1;
        Character[] CH = new Character[ns+1];
        for(int r=0; r<=sum+1; r++) {
            boolean can_see = (r<R.length && R[r]) || (r-1>=0 && R[r-1]);
            if(!can_see) continue;
            int c = ns-r;
            if(c<0 || c>=n || r<0 || r>=n) continue;
            CH[r] = G[r][c];
        }

        for(int r=0; r<=sum+1; r++) {
            if(CH[r] != null) {
                char ch = CH[r];
                boolean[] NR = new boolean[ns+1];
                for(int rr=0; rr<=sum+1; rr++)
                    if(CH[rr]!=null && CH[rr] == ch) {
                        NR[rr] = true;
                        CH[rr] = null;
                    }
                ans = Math.max(ans, ch_to_val(ch,first) - f(ns, NR, !first));
            }
        }
        F.put(key, ans);
        return ans;
    }
}


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

public class CF1342E extends PrintWriter {
	CF1342E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1342E o = new CF1342E(); o.main(); o.flush();
	}

	static final int MD = 998244353;
	int[] ff, gg;
	long power(int a, int k) {
		if (k == 0)
			return 1;
		long p = power(a, k >> 1);
		p = p * p % MD;
		if ((k & 1) == 1)
			p = p * a % MD;
		return p;
	}
	long ch(int n, int k) {
		return (long) ff[n] * gg[k] % MD * gg[n - k] % MD;
	}
	void main() {
		int n = sc.nextInt();
		long k_ = sc.nextLong();
		if (k_ >= n) {
			println(0);
			return;
		}
		int c = n - (int) k_;
		ff = new int[n + n];
		gg = new int[n + n];
		for (int f = 1, i = 0; i < n + n; i++) {
			gg[i] = (int) power(ff[i] = f, MD - 2);
			f = (int) ((long) f * (i + 1) % MD);
		}
		long ans = 0;
		for (int a = 1; a <= c; a++) {
			long x = power(a, n) * ch(c, a) % MD;
			ans += (c - a) % 2 == 0 ? x : -x;
		}
		if ((ans %= MD) < 0)
			ans += MD;
		ans = ans * ch(n, c) % MD;
		if (k_ > 0)
			ans = ans * 2 % MD;
		println(ans);
	}
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.math.BigInteger;
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;
        Parser in = new Parser(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    int mod = 1000000007;

    public void solve(int testNumber, Parser in, OutputWriter out) {
        long n = in.nextLong();
        int k = in.nextInt();

        long[][] pas = MathUtils.pas(41, mod);
        Matrix a = new Matrix(83);

        a.a[0][0] = 1;
        a.a[0][k+1] = 1;

        for (int pot = 0; pot <= 40; pot++) {
            for (int coef = 0; coef <= pot; coef++) {
                a.a[pot+1][coef+1] = pas[pot][coef];
                a.a[pot+1][coef+42] = (pas[pot][coef] * ((1L << (pot-coef)) % mod)) % mod;
            }
        }

        for (int pot = 0; pot <= 40; pot++) {
            a.a[pot+42][pot+1] = 1;
        }

        Matrix b = new Matrix(83);
        for (int i = 1; i <= 42; i++) b.a[i][0] = 1;

        a = a.modpow(n, mod);
        a = a.multiply(b, mod);
        /*for (int i = 0; i < 83; i++) {
            System.out.println("i " + i + " elem: " + a.a[i][0]);
        }*/

        out.println(a.a[0][0]);
    }
}

class Parser
{
    private BufferedReader din;
    private StringTokenizer tokenizer;

    public Parser(InputStream in)
    {
        din = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

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

    }

class OutputWriter extends PrintWriter {
    public OutputWriter(Writer out) {
        super(out);
    }

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

    }

class MathUtils {

    public static long[][] pas(int n, int mod) {
        long[][] ret = new long[n+1][n+1];

        for (int i = 0; i <= n; i++) {
            ret[i][0] = 1;
            for (int j = 1; j <= i; j++) {
                ret[i][j] = (ret[i-1][j-1] + ret[i-1][j]) % mod;
            }
        }

        return ret;
    }

    }

class Matrix {
    int n;
    long a[][];

    public Matrix(int n) {
        this.n = n;
        a = new long[n][n];
    }

    public static Matrix identity(int n) {
        Matrix ret = new Matrix(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ret.a[i][j] = 0;
            }
            ret.a[i][i] = 1;
        }

        return ret;
    }

    Matrix multiply(Matrix b, long mod) {
        Matrix resp = new Matrix(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                resp.a[i][j] = 0;
                for (int k = 0; k < n; k++) {
                    resp.a[i][j] = (resp.a[i][j] + a[i][k] * b.a[k][j]) % mod;
                }
            }
        }

        return resp;
    }

    Matrix modpow(long exp, long mod) {
        if (exp == 0) return identity(n);
        if (exp == 1) return this;

        Matrix h = modpow(exp/2, mod);
        h = h.multiply(h, mod);
        if (exp % 2 == 1) h = h.multiply(this, mod);

        return h;
    }

    }


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

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

public class D {

	final static boolean autoflush = false;

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

	Integer [] A;
	int N; int [] Q; int [][] R;

	public D () {
		N = sc.nextInt();
		A = sc.nextInts();

		if (N == 1)
			exit(1);

		next: for (int i : rep(1, N)) {
			for (int j : rep(i))
				for (int k : rep(i))
					if (A[j] + A[k] == A[i])
						continue next;
			exit(-1);
		}

		Map<Integer, Integer> M = new TreeMap<Integer, Integer>();
		for (int i : rep(N))
			M.put(A[i], i);

		Q = new int [N];
		R = new int [N][N];

		for (int i : rep(N))
			for (int j : rep(i))
				if (M.containsKey(A[i] - A[j])) {
					int k = M.get(A[i] - A[j]);
					Q[i] |= (1 << j);
					R[i][j] = k;
				}

		H = new int [1 << (N-1)]; fill(H, -1);

		int res = solve(1, 1);
		assert res <= N;
		exit(res);
	}

	int [] H;

	int solve(int X, int J) {
		int B = (X & Q[J]);
		if (B == 0)
			return H[X] = INF;

		for (int i = 0; i < J; ++i) {
			int U = (1 << i), V = (1 << R[J][i]);
			if ((B&U) != 0 && (B&V) != 0)
				break;
			if (i == J-1)
				return H[X] = INF;
		}

		if (J == N-1)
			return H[X] = Integer.bitCount(X);

		int Y = (X | (1 << J)), res = INF;
		for (int j = 0; j < J; ++j) {
			int W = (1 << j);
			if ((Y & W) != 0) {
				int V = Y & (~W), R = H[V] == -1 ? solve(V, J+1) : H[V];
				res = min(res, R);
			}
		}
		int R = H[Y] == -1 ? solve(Y, J+1) : H[Y];
		res = min(res, R);
		return H[X] = res;
	}

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

	static int [] rep(int N) { return rep(0, N); }
	static int [] rep(int S, int T) { int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	static int [] req(int S, int T) { return rep(S, T+1); }

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

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	final static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

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

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

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

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

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next ().toCharArray ();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i : rep(L.length))
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i : rep(L.length))
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i : rep(L.length))
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		public String [] next (int N) {
			String [] res = new String [N];
			for (int i : rep(N))
				res[i] = sc.next();
			return res;
		}

		public Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i : rep(N))
				res[i] = sc.nextInt();
			return res;
		}

		public Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i : rep(N))
				res[i] = sc.nextLong();
			return res;
		}

		public Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i : rep(N))
				res[i] = sc.nextDouble();
			return res;
		}

		public String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i : rep(N))
				res[i] = sc.nextStrings();
			return res;
		}

		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i : rep(N))
				res[i] = sc.nextInts();
			return res;
		}

		public Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i : rep(N))
				res[i] = sc.nextLongs();
			return res;
		}

		public Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i : rep(N))
				res[i] = sc.nextDoubles();
			return res;
		}

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

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner (BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print (Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint (Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	static void NO() {
		throw new Error("NO!");
	}

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

	static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i : rep(L))
				append(b, Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		} else
			b.append(delim).append(o);
	}

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

	static void statics() {
		abs(0);
		valueOf(0);
		asList(new Object [0]);
		reverseOrder();
	}

	public static void main (String[] args) {
		new D();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out, autoflush);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


//package com.company;

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

public class Main {

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

        String s = in.readLine();
        String ss[] = s.split(" ");

        int n = Integer.parseInt(ss[0]);
        int k = Integer.parseInt(ss[1]);

        String number = in.readLine();
        if (k == 0)
        {
            System.out.println(number);
        }
        else if(n == 1)
        {
            System.out.println("0");
        }
        else
        {
            StringBuffer tmp = new StringBuffer();
            tmp.append("1");

            if(number.charAt(0) != '1')
                k--;

            int counter = 1;
            while(k > 0 && counter < n)
            {
                if(number.charAt(counter) != '0')
                {
                     k--;
                }
                counter++;
                tmp.append("0");
            }

            if(counter < n)
                tmp.append(number.substring(counter));

            System.out.println(tmp.toString());
        }
    }
}


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.InputStreamReader;
import java.io.InputStream;

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

    static class DTriFiguri {
        static int N;
        int M = 305;
        int INF = (int) 1e9;
        DTriFiguri.Point[] possibleKnight = new DTriFiguri.Point[]{
                DTriFiguri.Point.of(2, 1),
                DTriFiguri.Point.of(-2, 1),
                DTriFiguri.Point.of(2, -1),
                DTriFiguri.Point.of(-2, -1),
                DTriFiguri.Point.of(1, 2),
                DTriFiguri.Point.of(-1, 2),
                DTriFiguri.Point.of(1, -2),
                DTriFiguri.Point.of(-1, -2)
        };
        DTriFiguri.Point[][] dist = new DTriFiguri.Point[M][M];

        {

        }

        private boolean in(DTriFiguri.Point p) {
            return 0 <= p.x && p.x < N && 0 <= p.y && p.y < N;
        }

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

            N = in.nextInt();
            DTriFiguri.Point[] pos = new DTriFiguri.Point[N * N];
            int[][] A = new int[N][N];
            for (int x = 0; x < N; x++) {
                for (int y = 0; y < N; y++) {
                    A[x][y] = in.nextInt() - 1;
                    pos[A[x][y]] = DTriFiguri.Point.of(x, y);

                }
            }

            for (int i = 0; i < M; i++) {
                for (int j = 0; j < M; j++) {
//                Arrays.fill(dist[i], Point.of(INF, INF));
                    dist[i][j] = DTriFiguri.Point.of(INF, INF);
                }
            }
            for (int i = 0; i < M; i++)
//            for (int j = 0; j < M; j++)
//                if (i == j)
                dist[i][i] = DTriFiguri.Point.of(0, 0);

            for (int x = 0; x < N; x++) {
                for (int y = 0; y < N; y++) {
                    //knight
                    for (int i = 0; i < possibleKnight.length; i++) {
                        int nx = x + possibleKnight[i].x;
                        int ny = y + possibleKnight[i].y;
                        if (in(DTriFiguri.Point.of(nx, ny))) {
                            dist[DTriFiguri.Point.hash(x, y, 0)][DTriFiguri.Point.hash(nx, ny, 0)] = DTriFiguri.Point.of(1, 0);
                        }
                    }
                    //bishop
                    for (int i = -N + 1; i <= N - 1; i++) {
                        int nx = x + i;
                        int ny = y + i;
                        if (in(DTriFiguri.Point.of(nx, ny)))
                            dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);

                        ny = y - i;
                        if (in(DTriFiguri.Point.of(nx, ny)))
                            dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);
                    }

                    //rook
                    for (int i = 0; i < N; i++) {
                        int nx = i;
                        int ny = y;
//                    if (in(Point.of(nx, ny)))
                        dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);
                        nx = x;
                        ny = i;
//                    if (in(Point.of(nx, ny)))
                        dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);

                    }

                    for (int i = 0; i < 3; i++) {
                        for (int j = 0; j < 3; j++) {
                            if (i != j) {
                                dist[DTriFiguri.Point.hash(x, y, i)][DTriFiguri.Point.hash(x, y, j)] = DTriFiguri.Point.of(1, 1);
                            }
                        }
                    }

                }
            }

            for (int k = 0; k < M; k++) {
                for (int i = 0; i < M; i++) {
                    for (int j = 0; j < M; j++) {
                        dist[i][j] = DTriFiguri.Point.min(dist[i][j], DTriFiguri.Point.sum(dist[i][k], dist[k][j]));
                    }
                }
            }

            DTriFiguri.Point[][] dp = new DTriFiguri.Point[N * N][3];
            for (int i = 0; i < N * N; i++) {
                for (int j = 0; j < 3; j++) {
                    dp[i][j] = DTriFiguri.Point.of(INF, INF);
                }
            }

            dp[0][0] = dp[0][1] = dp[0][2] = DTriFiguri.Point.of(0, 0);

            for (int i = 0; i < N * N - 1; i++)
                for (int j = 0; j < 3; j++)
                    for (int k = 0; k < 3; k++)
                        dp[i + 1][k] = DTriFiguri.Point.min(
                                dp[i + 1][k],
                                DTriFiguri.Point.sum(dp[i][j], dist[DTriFiguri.Point.hash(pos[i].x, pos[i].y, j)][DTriFiguri.Point.hash(pos[i + 1].x, pos[i + 1].y, k)])
                        );

            DTriFiguri.Point ans = DTriFiguri.Point.of(INF, INF);
            ans = DTriFiguri.Point.min(ans, dp[N * N - 1][0]);
            ans = DTriFiguri.Point.min(ans, dp[N * N - 1][1]);
            ans = DTriFiguri.Point.min(ans, dp[N * N - 1][2]);

            out.print(ans.toString());
        }

        private static class Point {
            int x;
            int y;

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

            public static DTriFiguri.Point of(int x, int y) {
                return new DTriFiguri.Point(x, y);
            }

            public static int hash(int x, int y, int p) {
                return x * N * 3 + y * 3 + p;
            }

            public static DTriFiguri.Point min(DTriFiguri.Point a, DTriFiguri.Point b) {
                if (a.x == b.x) {
                    return a.y < b.y ? a : b;
                }
                return a.x < b.x ? a : b;
            }

            public static DTriFiguri.Point sum(DTriFiguri.Point point1, DTriFiguri.Point point) {
                return DTriFiguri.Point.of(point1.x + point.x, point1.y + point.y);
            }

            public String toString() {
                return x + " " + y;
            }

        }

    }

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

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

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

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

    }
}


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

public class LuckyTickets {
    // 2^23*7*17+1
    private static final int MOD = 998244353;
    // ROOT^(2^23)=1 & ROOT^(2^22)!=1
    private static final int ROOT = 15311432;
    private static final int INVROOT = 469870224;

    private static int bitReverse(int n, int k) {
        return Integer.reverse(n) >>> (32 - k);
    }

    private static long modInv(int a) {
        return modPow(a, MOD - 2);
    }

    private static long modPow(int a, int p) {
        if (p == 0) {
            return 1;
        }
        long half = modPow(a, p / 2);
        long ans = (half * half) % MOD;
        if (p % 2 == 1) {
            ans = (ans * a) % MOD;
        }
        return ans;
    }

    // my first fft, LETS DO THIS!!
    // coef.length = 2^k
    private static void numberTheoreticTransform(long[] coef, int k, boolean inverse) {
        int baseRoot = inverse ? INVROOT : ROOT;
        long root = modPow(baseRoot, (int) modPow(2, 23 - k));
        long[] roots = new long[k];
        roots[k - 1] = root;
        for (int i = k - 1; i > 0; i--) {
            roots[i - 1] = (roots[i] * roots[i]) % MOD;
        }
        for (int s = 0; s < k; s++) {
            int len = 1 << s;
            for (int st = 0; st < coef.length; st += 2 * len) {
                // combine the vectors starting at st and st + len
                long curRoot = 1;
                for (int j = st; j < st + len; j++) {
                    long t = (curRoot * coef[j + len]) % MOD;
                    long u = coef[j];
                    coef[j] = (u + t) % MOD;
                    coef[j + len] = (u - t) % MOD;
                    curRoot = (roots[s] * curRoot) % MOD;
                }
            }
        }
        return;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() / 2;
        int m = sc.nextInt();
        int[] nums = new int[m];
        for (int i = 0; i < m; i++) {
            nums[i] = sc.nextInt();
        }
        Arrays.sort(nums);
        int min_size = n * nums[m - 1] + 2;
        int k = 0;
        int size = 1;
        while (size < min_size) {
            size *= 2;
            k++;
        }
        long[] a = new long[size];
        for (int i = 0; i < nums.length; i++) {
            a[bitReverse(nums[i], k)] = 1;
        }
        numberTheoreticTransform(a, k, false);
        for (int i = 0; i < size; i++) {
            a[i] = modPow((int) a[i], n);
        }
        long[] temp = new long[size];
        for (int i = 0; i < size; i++) {
            temp[bitReverse(i, k)] = (a[i]) % MOD;
        }
        a = temp;
        numberTheoreticTransform(a, k, true);
        long ans = 0;
        for (int i = 0; i < size; i++) {
            ans = (ans + a[i] * a[i]) % MOD;
        }
        long multiplier = modInv(size);
        System.out.println((((ans * multiplier) % MOD) * multiplier) % MOD);
    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1204E
   {
      static long MOD = 998244853L;
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         fac = new long[4001];
         invfac = new long[4001];
         fac[0] = invfac[0] = 1L;
         for(int i=1; i <= 4000; i++)
         {
            fac[i] = (fac[i-1]*i)%MOD;
            invfac[i] = power(fac[i], MOD-2, MOD);
         }
         long[][] zero = new long[N+1][M+1];
         Arrays.fill(zero[0], 1L);
         for(int a=1; a <= N; a++)
            for(int b=a; b <= M; b++)
               zero[a][b] = (zero[a-1][b]+zero[a][b-1])%MOD;
         long[][] dp = new long[N+1][M+1];
         for(int a=0; a <= N; a++)
            dp[a][0] = a;
         for(int a=1; a <= N; a++)
            for(int b=1; b <= M; b++)
            {
               long temp = (dp[a-1][b]+dp[a][b-1])%MOD;
               temp = (temp+cnt(a-1,b)-cnt(a,b-1)+MOD)%MOD;
               dp[a][b] = (temp+zero[a][b-1])%MOD;
            }
         System.out.println(dp[N][M]);
      }
      static long fac[];
      static long invfac[];
      public static long cnt(int a, int b)
      {
         long val = fac[a+b];
         val = (val*invfac[a])%MOD;
         return (val*invfac[b])%MOD;
      }
      public static long power(long x, long y, long p)
      {
          long res = 1L;
          x = x % p;
          while (y > 0)
          {
              if((y & 1)==1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
   }


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

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

        solve(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());
    }

    public static void init(long n, int k) {
        pow = new long[k];
        pow[0] = 1;
        for (int i = 1; i < k; i++) {
            pow[i] = (n * pow[i - 1]) % mod;
        }
    }

    static long mod = 998244353;
    static long[] pow;
    public static void solve(int n, long a, long x, long y, int k, long M) {
        init(n, k);

        int gcdR = gcdRange(k - 1);

        long[][] r = new long[gcdR][k + 1];

        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < gcdR; j++) {
                int jump = j - (j % (k + 1 - i));
                r[j][i] = (((n - 1) * r[j][i - 1]) + (r[jump][i - 1] + j * pow[i - 1])) % mod;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += r[(int)(a % gcdR)][k] + ((((a / gcdR) * gcdR * k) % mod) * pow[k - 1]) % mod;
            sum %= mod;
            a = (a * x + y) % M;
        }

        System.out.println(sum);
    }

    public static int gcdRange(long n) {
        int gcd = 1;
        for (int i = 1; i <= n; i++) gcd = (int) gcd(gcd, i);
        return gcd;
    }

    public static long gcd(long a, long b) {
        return a * b / ggt(a, b);
    }

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            G2PlaylistForPolycarpHardVersion solver = new G2PlaylistForPolycarpHardVersion();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class G2PlaylistForPolycarpHardVersion {
        Modular mod = new Modular(1e9 + 7);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            int[][] musics = new int[n][2];
            int[] cnts = new int[4];
            for (int i = 0; i < n; i++) {
                musics[i][0] = in.readInt();
                musics[i][1] = in.readInt();
                cnts[musics[i][1]]++;
            }

            int c1 = cnts[1];
            int c2 = cnts[2];
            int c3 = cnts[3];

            int[][][][] comp = new int[c1 + 1][c2 + 1][c3 + 1][4];
            for (int i = 0; i <= c1; i++) {
                for (int j = 0; j <= c2; j++) {
                    for (int k = 0; k <= c3; k++) {
                        for (int t = 0; t < 4; t++) {
                            if (i == 0 && j == 0 && k == 0) {
                                comp[i][j][k][t] = 1;
                                continue;
                            }
                            if (i > 0 && t != 1) {
                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i - 1][j][k][1], i));
                            }
                            if (j > 0 && t != 2) {
                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j - 1][k][2], j));
                            }
                            if (k > 0 && t != 3) {
                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j][k - 1][3], k));
                            }
                        }
                    }
                }
            }

            int[][][][] last = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];
            int[][][][] next = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];

            last[0][0][0][0] = 1;
            int t1 = 0;
            int t2 = 0;
            int t3 = 0;
            for (int[] music : musics) {
                int m1 = music[1];
                int m0 = music[0];
                if (m1 == 1) {
                    t1++;
                } else if (m1 == 2) {
                    t2++;
                } else {
                    t3++;
                }
                for (int i = 0; i <= t1; i++) {
                    for (int j = 0; j <= t2; j++) {
                        for (int k = 0; k <= t3; k++) {
                            for (int t = 0; t <= m; t++) {
                                next[i][j][k][t] = last[i][j][k][t];
                                if (t < m0) {
                                    continue;
                                }
                                if (m1 == 1 && i > 0) {
                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i - 1][j][k][t - m0]);
                                } else if (m1 == 2 && j > 0) {
                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j - 1][k][t - m0]);
                                } else if (m1 == 3 && k > 0) {
                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j][k - 1][t - m0]);
                                }
                            }
                        }
                    }
                }

                int[][][][] tmp = last;
                last = next;
                next = tmp;
            }

            int ans = 0;
            for (int i = 0; i <= c1; i++) {
                for (int j = 0; j <= c2; j++) {
                    for (int k = 0; k <= c3; k++) {
                        ans = mod.plus(ans, mod.mul(last[i][j][k][m], comp[i][j][k][0]));
                    }
                }
            }

            out.println(ans);
        }

    }

    static class Modular {
        int m;

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}