Let's introduce the designation <image>, where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.

We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and aсba can be obtained from string xacbac, and strings bx and aaa cannot be obtained from it.

Sereja has two strings, w = [a, b] and q = [c, d]. He wants to find such maximum integer p (p > 0), that [q, p] can be obtained from string w.

Input

The first line contains two integers b, d (1 ≤ b, d ≤ 107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.

Output

In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.

Examples

Input

10 3
abab
bab


Output

3
import java.util.Map;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.InputStream;

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

class TaskB {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int b = in.nextInt();
        int d = in.nextInt();
        final String aS = in.next();
        char[] a = aS.toCharArray();
        final String cS = in.next();
        char[] c = cS.toCharArray();

        int pA = 0;
        int pC = 0;

        boolean possible = true;
        for (int i = 0; i < c.length; i++) {
            possible &= aS.contains(String.valueOf(c[i]));
        }

        if (!possible) {
            out.println(0);
        } else {
            Map<Integer, Integer> startPositions = new HashMap<Integer, Integer>();
            int startPosition = -1;
            int pos = -1;
            boolean cycleFound = false;
            while (true) {
                boolean found = false;
                for (int i = pos + 1; i < a.length * b; i++) {
                    if (c[0] == a[i % a.length]) {
                        pos = i;
                        found = true;
                        break;
                    }
                }
                if (!found) break;
                if (startPositions.get(pos % a.length) != null) {
                    startPosition = startPositions.get(pos % a.length);
                    cycleFound = true;
                    break;
                } else {
                    startPositions.put(pos % a.length, pos);
                }
                for (int i = 1; i < c.length; i++) {
                    for (int j = pos + 1; j < a.length * b; j++) {
                        if (c[i] == a[j % a.length]) {
                            pos = j;
                            break;
                        }
                    }
                }
            }

            if (!cycleFound) {
                pos = -1;
                int count = 0;
                while (true) {
                    boolean ok = true;
                    for (int i = 0; i < c.length; i++) {
                        boolean found = false;
                        for (int j = pos + 1; j < a.length * b; j++) {
                            if (c[i] == a[j % a.length]) {
                                pos = j;
                                found = true;
                                break;
                            }
                        }
                        ok &= found;
                    }
                    if (!ok) break;
                    count++;
                }
                out.println(count / d);
            } else {
                pos = startPosition - 1;
                while (true) {
                    for (int i = pos + 1; i < a.length * b; i++) {
                        if (c[0] == a[i % a.length]) {
                            pos = i;
                            break;
                        }
                    }
                    if (pos % a.length == startPosition % a.length && pos != startPosition) {
                        pA = (pos - startPosition) / a.length;
                        break;
                    }

                    for (int i = 1; i < c.length; i++) {
                        for (int j = pos + 1; j < a.length * b; j++) {
                            if (c[i] == a[j % a.length]) {
                                pos = j;
                                break;
                            }
                        }
                    }
                    pC++;
                }
//            out.println(pA + " " + pC);

                int p = (a.length * b - startPosition) / (d * pA * a.length) * pC;

                pos = -1;
                int count = 0;
                while (true) {
                    boolean ok = true;
                    for (int i = 0; i < c.length; i++) {
                        boolean found = false;
                        for (int j = pos + 1; j < startPosition; j++) {
                            if (c[i] == a[j % a.length]) {
                                pos = j;
                                found = true;
                                break;
                            }
                        }
                        ok &= found;
                    }
                    if (!ok) break;
                    count++;
                }

                pos = startPosition + p * d / pC * pA * a.length - 1;
                while (true) {
                    boolean ok = true;
                    for (int i = 0; i < c.length; i++) {
                        boolean found = false;
                        for (int j = pos + 1; j < a.length * b; j++) {
                            if (c[i] == a[j % a.length]) {
                                pos = j;
                                found = true;
                                break;
                            }
                        }
                        ok &= found;
                    }
                    if (!ok) break;
                    count++;
                }
                p += count / d;

                out.println(p);
            }
        }
    }
}

