Let's introduce the designation , 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.

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.

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

import sys
debug = False
def solve(a, b, c, d):
    for i in c:
        if i not in a:
            return 0
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 1
    cnt2 = 0
    phases = []
    phases2 = []

    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1
            if ind2 == len(c):
                #word finished!
                cnt2 += 1
                ind2 = 0
                #check phase
                if ind1 in phases:
                    #period!
                    cnt1_, cnt2_ = phases2[phases.index(ind1)]
                    step1 = cnt1 - cnt1_
                    step2 = cnt2 - cnt2_
                    cnt = (b-cnt1)/step1
                    cnt1 += step1 * cnt
                    cnt2 += step2 * cnt
                    phases = []
                    phases2 = []
                #save phase
                phases.append(ind1)
                phases2.append([cnt1, cnt2])

        ind1 += 1
        if ind1 == len(a):
            cnt1 += 1
            ind1 = 0
            if cnt1 > b:
                return cnt2 / d
    #answ
    val2 = phases2[-1]
    val1 = phases2[phases.index(ind1)]

    step1 = val2[0] - val1[0]
    step2 = val2[1] - val1[1]

    if debug:
        print str(val1[0]) + " -- > " + str(val1[1])
        print str(val2[0]) + " -- > " + str(val2[1])

    res = step2 * b / (step1 * d)
    res = (b - val2[0]) * step2 / (step1 * d) + val2[1]
    if res < 0:
        return 0
    else:
        return res

if not debug:
    b, d = map(int, sys.stdin.readline().split())

    a = sys.stdin.readline().split()[0]
    c = sys.stdin.readline().split()[0]
    print str(solve(a, b, c, d))
else:
    vals = []
    vals.append([841, 7, 'qjqhrksmvedtqldrqgchhsofokfcovut' ,'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc', 5])
    vals.append([933, 5, 'abaabdcbbabacbdddadbbb', 'babbadbaaadbbbbaabbaabccbbdbadbbbbbbdbcbdbaaadbdbdbbbbdcbbdcbdaadbd', 15])
    vals.append([875, 10, 'hjeaiemqfliohlicmhndhbfdmlmcnjjgbg', 'hojqhmbgjlfmlliimlhahfeihgmhhhnbmebhgnfhgmhfjqhmlnnddgmqldelnhebi', 4])
    vals.append([320672, 1, 'wyyojuothwmlvrglfzdzdbtubxuoffvncrswsaznmoijoi', 'ttvlvzxcvczuagwzgbfuwmmt', 40084])
    vals.append([5608475, 1, 'gbagadghfaedhddefgbehbbdedefbaaeddachgebhbcgahfdchffhbhfahhdegdhdfbccgefhcdhhcdfgdgfhcdffaacch', 'fgfadaaecdgabeahcacadcbfhhe', 1869491])
    vals.append([1263204, 1, 'dcbabceabbaebddaaecbddaceaedacddadadcbbadbdccdecdacdcaadbceeddccbceaade', 'abddbccbdca', 1894805])
    vals.append([100, 1, 'bca', 'abc', 99])
    vals.append([541, 9, 'bxhwcmunbdxcatppdsw', 'shbppncwbnsxxnxunwsbncpdchcbcspdcppdchmbbcuapphpdxbpcswcxpxpdscxpddbcppdxhpxbuxxdbpdpuudb', 1])
    vals.append([9447267, 1, 'cbdcbdbcdacbcabddbaabcbacbabcaacbabaccddcbbdbbaddcbcbaaadc', 'bbbbdbcbbbdbdbcdcacccbdcadadbacbcccc', 4723633])
    vals.append([1181362, 3, 'fckmaalkicfakhcbiglkekajmadjkj', 'zfkjkjgkmjhfkackkhhjalgkkclcklabggk', 0])
    for val in vals:
        b, d, a, c, answer = val
        res = solve(a, b, c, d)
        if res == answer:
            print '++++++++++++++++++++++++++++'
            pass
        else:
            print '----------------------------'
            print val
            print res
            print '----------------------------'
            sys.stdin.readline()

from itertools import repeat,chain
from fractions import gcd

def eternal(c,d, n = None):

    while True:

        yield chain.from_iterable(repeat(c,d))

def cyclic_array(arr):

    n = len(arr)
    def cyclar(i):

        return arr[i % n]

    return cyclar
def find_repeat(enum,q_r_gen, a_n):

    ac_count =0
    a_count = 0
    remainders ={}
    tempq=''
    tempa = ''
    for q,q_r in enumerate(q_r_gen):

        tempq=''
        for c_c in q_r:
            tempq= tempq +c_c
            for a_count,a_c in enum:
                if a_c == c_c:
                    tempa = tempa +a_c
                    ac_count+=1
                    break
            #print len(tempa),len(tempq)
        if (a_count % a_n) in remainders:

            #print tempq[:20],tempa[:20]
            break
        else:

            remainders[(a_count % a_n)]=(a_count,q)

    repeat_length = a_count - remainders[a_count % a_n][0]
    q_count = q-remainders[a_count % a_n][1]

    return remainders[a_count % a_n][0],repeat_length,q_count

def main(a,b,c,d):

    #print a, c

    a_r = chain.from_iterable(repeat(a,b))

    #print "".join(chain.from_iterable(repeat(a,b)))

    enum =enumerate(a_r)

    q_r_gen = eternal(c,d)

    i = 0
    flag = True

    if len(a) > len(c)*d:
        multiplier =1
        start,repeat_length,q_count = find_repeat(enum,q_r_gen, len(a))

    else:
        multiplier =((len(c)*d)//len(a))+1
        #print "Multi",multiplier
        enum2 = enumerate(chain.from_iterable(repeat(a*multiplier,b//multiplier)))
        start,repeat_length,q_count =find_repeat(enum2,q_r_gen, multiplier*len(a))

    if repeat_length >0:
        advance_n = (((len(a)*multiplier)*(b//multiplier))//repeat_length)-1
        advance = repeat_length * advance_n

        sofar = q_count * advance_n
    else:
        advance_n =0
        advance = 0
        sofar = 0

    #print advance_n,advance, repeat_length, len(a)*b, sofar , len(c)*d

    ca = cyclic_array(a)

    ra = iter(range(advance,len(a)*b))

    ac_count =0
    for q_r in q_r_gen:
        for i,c_c in enumerate(q_r):

            flag = False
            for a_count in ra:
                #print a_count

                if ca(a_count) == c_c:
                    ac_count+=1
                    flag = True
                    break

        if not flag:
            break

    print sofar + (ac_count // (len(c)*d))

if __name__ == "__main__":
    b,d = [int(s) for s in (raw_input()).split()]

    a = raw_input()

    c = raw_input()

    aset = set(a)
    cset = set(c)

    if cset.difference(aset):
        print 0

    elif a == c:

        print b // d

    else:

        main(a,b,c,d)

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print len_a
#print len_c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0
            return

    if (len_c == 1):
        print a.count(c) * b / d
        return

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    #print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    #print "cycle_end is " + str(cycle_end)
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - cycle_start) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    #print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    #print "rounds_before is " + str(rounds_before)
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
            p += 1
    #print "end"
    #print rounds_after
    print (rounds_before+rounds_between+rounds_after) / d

solve()

b, d = map(int,raw_input().strip().split())
a = raw_input()
c = raw_input()
la = len(a)
lc = len(c)

sa = set(a)
bad = False
for ch in c:
  if ch not in sa:
    bad = True
    break

if bad:
  print 0
else:
  def get_next(i):
    j = 0
    cross = 0
    while j < lc:
      if a[i] == c[j]:
        j += 1
      if i == 0:
        cross += 1
      i += 1
      if i >= la:
        i = 0
    return cross, i

  nex = {}
  for i in xrange(la):
    nex[i] = get_next(i)

  #print nex
  tym = {}
  stp = {}
  t = 0
  ans = 0
  ct = 0
  while t not in tym:
#    print t, ans, ct
    tym[t] = ans
    stp[t] = ct
    x, t = nex[t]
    if ans + x > b:
      break
    ct += 1
    ans += x
  #print tym

  if ans + x <= b:
    dtym = ans - tym[t]
    dstp = ct - stp[t]
    #print 'dtym', dtym
    #print 'dstp', dstp
    #while ans + dtym <= b:
    #  ans += dtym
    #  ct += dstp
    #ans + q * dtym <= b
    q = (b - ans) / dtym
    ans += q * dtym
    ct += q * dstp

    #print 'ans is', ans
    while True:
      x, t = nex[t]
      if ans + x > b:
        break
      ct += 1
      ans += x

  #print ct, ans

  print ct / d

rd = lambda : map(int, raw_input().split())
rep1, rep2 = rd()
s1 = raw_input()
s2 = raw_input()
for ch in s2:
  if not ch in s1:
    print 0
    exit()

d = {}
i = 0
j = 0
c1 = 1
c2 = 0
cicle_key = 0, 0
while True:
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1
  if (i, j) in d:
    cicle_key = (i, j)
    break
  d[(i, j)] = (c1, c2)
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1

rep1 -= c1
cicles_left = rep1 / (c1 - d[cicle_key][0])
c2 += cicles_left * (c2 - d[cicle_key][1])
rep1 -= cicles_left * (c1 - d[cicle_key][0])

i, j = cicle_key
c1 = 0
while True:
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1

import sys

def solve(a, b, c, d):
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 0
    phases = []
    phases2 = []
    ahtung = False
    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1

        if ind2 == len(c):
            ind2 = 0
            #contained. lets check syn
            if ind1 in phases:
                #period!
                #print "period!"
                phases.append(ind1)
                phases2.append(cnt1)
                break
            phases.append(ind1)
            phases2.append(cnt1)

        ind1 += 1
        if ind1 == len(a):
            ahtung = (ind2!=0)
            ind1 = 0
            cnt1 += 1

        if cnt1 >= b:
            #all length of a reached
            return len(phases)/d

    #print phases
    #print phases2

    val = phases.pop(-1)
    cnt2 = len(phases)
    ind = len(phases) - phases[::-1].index(val) -1
    cnt2 -= ind
    #print "second in period = " + str(cnt2)
    per1 = phases2[-1] - phases2[ind]
    #print "first in period = " + str(per1)

    #print ahtung
    #if phases2[ind] == 0 or phases2[ind]==phases2[ind-1]:
    #    ahtung = False
    #else:
    #    ahtung = True
    #print ahtung
    res = cnt2 * b
    if ahtung:
        res -= 1
    res /= (per1 * d)
    #print res
    if res<0:
        res = 0
    return res

b, d = map(int, sys.stdin.readline().split())

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

if False:
    b, d = 841, 7
    a = 'qjqhrksmvedtqldrqgchhsofokfcovut'
    c = 'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc'

    b, d = 10,3
    a = 'abab'
    c = 'bab'

print solve(a, b, c, d)

import sys

def solve(a, b, c, d):
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 0
    phases = []
    phases2 = []
    ahtung = False
    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1

        if ind2 == len(c):
            ind2 = 0
            #contained. lets check syn
            if ind1 in phases:
                #period!
                #print "period!"
                phases.append(ind1)
                phases2.append(cnt1)
                break
            phases.append(ind1)
            phases2.append(cnt1)

        ind1 += 1
        if ind1 == len(a):
            ahtung = (ind2!=0)
            ind1 = 0
            cnt1 += 1

        if cnt1 >= b:
            #all length of a reached
            return len(phases)/d

    #print phases
    #print phases2

    val = phases.pop(-1)
    cnt2 = len(phases)
    ind = len(phases) - phases[::-1].index(val) -1
    cnt2 -= ind
    #print "second in period = " + str(cnt2)
    per1 = phases2[-1] - phases2[ind]
    #print "first in period = " + str(per1)

    if phases2[ind] == 0:
        ahtung = (phases2[-1] > 1)
    else:
        ahtung = (phases2[-1]-phases2[ind]>phases2[ind])
    #print ahtung
    #if phases2[ind] == 0 or phases2[ind]==phases2[ind-1]:
    #    ahtung = False
    #else:
    #    ahtung = True
    #print ahtung
    res = cnt2 * b

    if ahtung:
        res -= 1
    res /= (per1 * d)
    #print res
    if res<0:
        res = 0
    return res

b, d = map(int, sys.stdin.readline().split())

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

if True and False:
    b, d = 841, 7
    a = 'qjqhrksmvedtqldrqgchhsofokfcovut'
    c = 'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc'

    b, d = 10,3
    a = 'abab'
    c = 'bab'

    b, d = 1263204, 1
    a = 'dcbabceabbaebddaaecbddaceaedacddadadcbbadbdccdecdacdcaadbceeddccbceaade'
    c = 'abddbccbdca'

print solve(a, b, c, d)

import sys

def solve(a, b, c, d):
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 1
    cnt2 = 0
    phases = []
    phases2 = []

    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1
            if ind2 == len(c):
                #word finished!
                cnt2 += 1
                ind2 = 0
                #check phase
                if ind1 in phases:
                    #period!
                    phases.append(ind1)
                    phases2.append([cnt1, cnt2])

                    break

                #save phase
                phases.append(ind1)
                phases2.append([cnt1, cnt2])

        ind1 += 1
        if ind1 == len(a):
            cnt1 += 1
            ind1 = 0
            if cnt1 > b:
                return cnt2 / d

    val2 = phases2[-1]
    val1 = phases2[phases.index(ind1)]

    step1 = val2[0] - val1[0]
    step2 = val2[1] - val1[1]

    delta = -val2[0]*step2/step1+val2[1]
    if False:
        print str(val1[0]) + " -- > " + str(val1[1])
        print str(val2[0]) + " -- > " + str(val2[1])
        print "delta = " + str(delta)
    res = step2 * b / (step1 * d) + delta
    if res < 0:
        return 0
    else:
        return res

if True:
    b, d = map(int, sys.stdin.readline().split())

    a = sys.stdin.readline().split()[0]
    c = sys.stdin.readline().split()[0]
    print str(solve(a, b, c, d))
else:
    vals = []
    vals.append([841, 7, 'qjqhrksmvedtqldrqgchhsofokfcovut' ,'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc', 5])
    vals.append([933, 5, 'abaabdcbbabacbdddadbbb', 'babbadbaaadbbbbaabbaabccbbdbadbbbbbbdbcbdbaaadbdbdbbbbdcbbdcbdaadbd', 15])
    vals.append([875, 10, 'hjeaiemqfliohlicmhndhbfdmlmcnjjgbg', 'hojqhmbgjlfmlliimlhahfeihgmhhhnbmebhgnfhgmhfjqhmlnnddgmqldelnhebi', 4])
    vals.append([320672, 1, 'wyyojuothwmlvrglfzdzdbtubxuoffvncrswsaznmoijoi', 'ttvlvzxcvczuagwzgbfuwmmt', 40084])
    vals.append([5608475, 1, 'gbagadghfaedhddefgbehbbdedefbaaeddachgebhbcgahfdchffhbhfahhdegdhdfbccgefhcdhhcdfgdgfhcdffaacch', 'fgfadaaecdgabeahcacadcbfhhe', 1869491])
    vals.append([1263204, 1, 'dcbabceabbaebddaaecbddaceaedacddadadcbbadbdccdecdacdcaadbceeddccbceaade', 'abddbccbdca', 1894805])
    vals.append([100, 1, 'bca', 'abc', 99])
    for val in vals:
        b, d, a, c, answer = val
        res = solve(a, b, c, d)
        if res == answer:
            print '++++++++++++++++++++++++++++'
            pass
        else:
            print '----------------------------'
            print val
            print res
            print '----------------------------'
            sys.stdin.readline()

import sys

def solve(a, b, c, d):
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 0
    phases = []
    phases2 = []
    ahtung = False
    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1

        if ind2 == len(c):
            ind2 = 0
            #contained. lets check syn
            if ind1 in phases:
                #period!
                #print "period!"
                phases.append(ind1)
                phases2.append(cnt1)
                break
            phases.append(ind1)
            phases2.append(cnt1)

        ind1 += 1
        if ind1 == len(a):
            ahtung = (ind2!=0)
            ind1 = 0
            cnt1 += 1

        if cnt1 >= b:
            #all length of a reached
            return len(phases)/d

    #print phases

    val = phases.pop(-1)
    cnt2 = len(phases)
    ind = len(phases) - phases[::-1].index(val) -1
    cnt2 -= ind
    #print "second in period = " + str(cnt2)
    per1 = phases2[-1] - phases2[ind]
    #print "first in period = " + str(per1)
    #print ahtung

    res = cnt2 * b / (per1 * d)
    if ahtung:
        res =- 1
    if res<0:
        res = 0
    return res

b, d = map(int, sys.stdin.readline().split())

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

#b, d = 10, 3
#a = 'bzabza'
#c = 'abz'
print solve(a, b, c, d)

import sys

def solve(a, b, c, d):
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 0
    phases = []
    phases2 = []
    ahtung = False
    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1

        if ind2 == len(c):
            ind2 = 0
            #contained. lets check syn
            if ind1 in phases:
                #period!
                #print "period!"
                phases.append(ind1)
                phases2.append(cnt1)
                break
            phases.append(ind1)
            phases2.append(cnt1)

        ind1 += 1
        if ind1 == len(a):
            ahtung = (ind2!=0)
            ind1 = 0
            cnt1 += 1

        if cnt1 >= b:
            #all length of a reached
            return len(phases)/d

    #print phases
    #print phases2

    val = phases.pop(-1)
    cnt2 = len(phases)
    ind = len(phases) - phases[::-1].index(val) -1
    cnt2 -= ind
    #print "second in period = " + str(cnt2)
    per1 = phases2[-1] - phases2[ind]
    #print "first in period = " + str(per1)

    #print ahtung
    #if phases2[ind] == 0 or phases2[ind]==phases2[ind-1]:
    #    ahtung = False
    #else:
    #    ahtung = True
    #print ahtung
    res = cnt2 * b

    if ahtung and False:
        res -= 1
    res /= (per1 * d)
    #print res
    if res<0:
        res = 0
    return res

b, d = map(int, sys.stdin.readline().split())

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

if False:
    b, d = 841, 7
    a = 'qjqhrksmvedtqldrqgchhsofokfcovut'
    c = 'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc'

    b, d = 10,3
    a = 'abab'
    c = 'bab'

print solve(a, b, c, d)

from itertools import repeat,chain
from fractions import gcd

def eternal(c,d, n = None):

    while True:

        yield chain.from_iterable(repeat(c,d))

def cyclic_array(arr):

    n = len(arr)
    def cyclar(i):

        return arr[i % n]

    return cyclar

def main():
    b,d = [int(s) for s in (raw_input()).split()]

    a = raw_input()

    c = raw_input()

    #print a, c

    a_r = chain.from_iterable(repeat(a,b))

    #print "".join(chain.from_iterable(repeat(a,b)))

    q_r_gen = eternal(c,d)

    i = 0
    flag = True

    remainders ={}
    a_count = 0

    ac_count =0

    enum =enumerate(a_r)

    for q,q_r in enumerate(q_r_gen):

        for c_c in q_r:
            for a_count,a_c in enum:
                if a_c == c_c:
                    ac_count+=1
                    break
        if (a_count % len(a)) in remainders:

            break
        else:

            remainders[(a_count % len(a))]=a_count

    #print remainders

    repeat_length = a_count - remainders[a_count % len(a)]

    if repeat_length >0:
        advance_n = ((len(a)*b)//repeat_length)
        advance = repeat_length * advance_n

        sofar = (repeat_length / (len(c)*d)) * advance_n
    else:
        advance = 0
        sofar = 0

    #print advance_n,advance, repeat_length, len(a)*b, sofar

    ca = cyclic_array(a)

    ra = iter(range(advance,len(a)*b))

    ac_count =0
    for q_r in q_r_gen:
        for i,c_c in enumerate(q_r):

            flag = False
            for a_count in ra:

                if ca(a_count) == c_c:
                    ac_count+=1
                    flag = True
                    break

        if not flag:
            break

    print sofar + (ac_count // (len(c)*d))

main()

from itertools import repeat,chain
from fractions import gcd

def eternal(c,d, n = None):

    while True:

        yield chain.from_iterable(repeat(c,d))

def cyclic_array(arr):

    n = len(arr)
    def cyclar(i):

        return arr[i % n]

    return cyclar
def find_repeat(enum,q_r_gen, a_n):

    ac_count =0
    a_count = 0
    remainders ={}

    for q,q_r in enumerate(q_r_gen):

        for c_c in q_r:
            for a_count,a_c in enum:
                if a_c == c_c:
                    ac_count+=1
                    break
        if (a_count % a_n) in remainders:

            print "found", a_count, remainders
            break
        else:

            remainders[(a_count % a_n)]=a_count

    repeat_length = a_count - remainders[a_count % a_n]

    return repeat_length

def main():
    b,d = [int(s) for s in (raw_input()).split()]

    a = raw_input()

    c = raw_input()

    #print a, c

    a_r = chain.from_iterable(repeat(a,b))

    #print "".join(chain.from_iterable(repeat(a,b)))

    enum =enumerate(a_r)

    q_r_gen = eternal(c,d)

    i = 0
    flag = True

    if len(a) > len(c):
        repeat_length = find_repeat(enum,q_r_gen, len(a))

    else:
        repeat_length = 0

    if repeat_length >0:
        advance_n = ((len(a)*b)//repeat_length)
        advance = repeat_length * advance_n

        sofar = (repeat_length / (len(c)*d)) * advance_n
    else:
        advance_n =0
        advance = 0
        sofar = 0

    #print advance_n,advance, repeat_length, len(a)*b, sofar

    ca = cyclic_array(a)

    ra = iter(range(advance,len(a)*b))

    ac_count =0
    for q_r in q_r_gen:
        for i,c_c in enumerate(q_r):

            flag = False
            for a_count in ra:

                if ca(a_count) == c_c:
                    ac_count+=1
                    flag = True
                    break

        if not flag:
            break

    print sofar + (ac_count // (len(c)*d))

main()

from itertools import repeat,chain
from fractions import gcd

def eternal(c,d, n = None):

    while True:

        yield chain.from_iterable(repeat(c,d))

def cyclic_array(arr):

    n = len(arr)
    def cyclar(i):

        return arr[i % n]

    return cyclar
def find_repeat(enum,q_r_gen, a_n):

    ac_count =0
    a_count = 0
    remainders ={}
    tempq=''
    tempa = ''
    for q,q_r in enumerate(q_r_gen):

        tempq=''
        for c_c in q_r:
            tempq= tempq +c_c
            for a_count,a_c in enum:
                if a_c == c_c:
                    tempa = tempa +a_c
                    ac_count+=1
                    break
            #print len(tempa),len(tempq)
        if (a_count % a_n) in remainders:

            #print tempq[:20],tempa[:20]
            break
        else:

            remainders[(a_count % a_n)]=(a_count,q)

    repeat_length = a_count - remainders[a_count % a_n][0]
    q_count = q-remainders[a_count % a_n][1]

    return remainders[a_count % a_n][0],repeat_length,q_count

def main():
    b,d = [int(s) for s in (raw_input()).split()]

    a = raw_input()

    c = raw_input()

    #print a, c

    a_r = chain.from_iterable(repeat(a,b))

    #print "".join(chain.from_iterable(repeat(a,b)))

    enum =enumerate(a_r)

    q_r_gen = eternal(c,d)

    i = 0
    flag = True

    if len(a) > len(c)*d:
        multiplier =1
        start,repeat_length,q_count = find_repeat(enum,q_r_gen, len(a))

    else:
        multiplier =((len(c)*d)//len(a))+1
        #print "Multi",multiplier
        enum2 = enumerate(chain.from_iterable(repeat(a*multiplier,b//multiplier)))
        start,repeat_length,q_count =find_repeat(enum2,q_r_gen, multiplier*len(a))

    if repeat_length >0:
        advance_n = (((len(a)*multiplier)*(b//multiplier))//repeat_length)
        advance = repeat_length * advance_n

        sofar = q_count * advance_n
    else:
        advance_n =0
        advance = 0
        sofar = 0

    #print advance_n,advance, repeat_length, len(a)*b, sofar , len(c)*d

    ca = cyclic_array(a)

    ra = iter(range(advance,len(a)*b))

    ac_count =0
    for q_r in q_r_gen:
        for i,c_c in enumerate(q_r):

            flag = False
            for a_count in ra:
                #print a_count

                if ca(a_count) == c_c:
                    ac_count+=1
                    flag = True
                    break

        if not flag:
            break

    print sofar + (ac_count // (len(c)*d))

main()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print a
#print c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0
            return

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    #print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    #print cycle_end
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - cycle_start) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    #print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
    #print "end"
    print (rounds_before+rounds_between+rounds_after) / d

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print a
#print c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    #print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    #print cycle_end
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - (i+1)) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    #print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
    #print "end"
    print (rounds_before+rounds_between+rounds_after) / d

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print a
#print c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0
            return

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    #print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    #print cycle_end
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - (i+1)) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    #print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
    #print "end"
    print (rounds_before+rounds_between+rounds_after) / d

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print len_a
#print len_c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0
            return
    if (len_c == 1):
        print a.count(c) * b
        return

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    print "cycle_end is " + str(cycle_end)
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - cycle_start) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    print "rounds_before is " + str(rounds_before)
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
            p += 1
    #print "end"
    print rounds_after
    print (rounds_before+rounds_between+rounds_after) / d

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

#print a
#print c
def find_g(a, key):
    '''Find smallest item greater thank key.
    '''
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    # process a to form a hash map : char -> indexs of char
    dic = dict()
    i = 0
    len_a = len(a)

    for char in a:
        if (dic.get(char) != None):
            dic[char].append(i)
        else:
            dic[char] = [i]
        i += 1

    #printD(dic)
    # process c now
    i = 0
    last_index = -1
    len_c = len(c)
    term = 0
    indexes = []

    #print "len_c is " + str(len_c)
    for i in xrange(len_c):
        char = c[i]
        if (dic.get(char) == None):
            print 0
        if (last_index < 0):
            index = find_g(dic.get(char), last_index)
        else:
            index = find_g(dic.get(char), last_index % len_a)
        if (index == -1):
            term += 1
            index = find_g(dic.get(char), -1)
        last_index = term * len_a + index
        if (last_index >= len_a * b):
            print 0
            return
        indexes.append(last_index)

    single_cycle = last_index + 1
    if (single_cycle < len_a):
        freq = 0
        # see how many can be found in one a
        for i in xrange(len_a):
            if a[i] == c[0]:
                if a[i:i+len_c] == c:
                    freq += 1
        print b * freq
        return
    elif (single_cycle % len_a == 0):
        print len_a * b / (single_cycle * d)
        return
    else:
        one_round = single_cycle / len_a + 1
        rounds = one_round + (one_round - 1) * d
        print 1 + (b - rounds) / (rounds - 1)
        return

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
len_a = len(a)
c = sys.stdin.readline().split()[0]
len_c = len(c)

#print len_a
#print len_c
def find_g(a, key):
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    starts = dict()
    start_round = dict()
    rounds_so_far = 0
    i = 0

    for char in c:
        if char not in a:
            print 0
            return

    for j in xrange(len_a*b):
        if a[j%len_a] == c[i%len_c]:
            if ((i+1) % len_c == 0):
                rounds_so_far += 1
            if (i % len_c == 0):
                if (starts.get(j%len_a) == None):
                    starts[j%len_a] = j
                    start_round[j] = rounds_so_far
                else:
                    break
            i += 1
    else:
        print rounds_so_far / d
        return

    cycle_start = starts[j%len_a]
    #print cycle_start
    cycle_end = j
    cycle_char = cycle_end - cycle_start
    #print "cycle_end is " + str(cycle_end)
    rounds_one_cycle = rounds_so_far - start_round[cycle_start]
    cycles = (len_a*b - cycle_start) / cycle_char
    rounds_between = rounds_one_cycle * cycles
    #print "rounds_between is " + str(rounds_between)
    rounds_before = start_round[cycle_start]
    rounds_after = 0

    p = 0
    for k in xrange(cycle_start+cycles*cycle_char, len_a*b):
        if a[k%len_a] == c[p%len_c]:
            if ((p+1) % len_c) == 0:
                rounds_after += 1
            p += 1
    #print "end"
    print (rounds_before+rounds_between+rounds_after) / d

solve()

import sys
from bisect import *

inputs = sys.stdin.readline().split()
b = int(inputs[0])
d = int(inputs[1])

a = sys.stdin.readline().split()[0]
c = sys.stdin.readline().split()[0]

#print a
#print c
def find_g(a, key):
    '''Find smallest item greater thank key.
    '''
    i = bisect_right(a, key)
    if i == len(a):
        return -1
    return a[i]

def printD(myDic):
    for key in myDic.keys():
        print key
        print myDic[key]
    print

def solve():
    # process a to form a hash map : char -> indexs of char
    dic = dict()
    i = 0
    len_a = len(a)

    for char in a:
        if (dic.get(char) != None):
            dic[char].append(i)
        else:
            dic[char] = [i]
        i += 1

    #printD(dic)
    # process c now
    i = 0
    last_index = -1
    len_c = len(c)
    term = 0
    indexes = []

    #print "len_c is " + str(len_c)
    for i in xrange(len_c):
        char = c[i]
        if (dic.get(char) == None):
            print 0
        if (last_index < 0):
            index = find_g(dic.get(char), last_index)
        else:
            index = find_g(dic.get(char), last_index % len_a)
        if (index == -1):
            term += 1
            index = find_g(dic.get(char), -1)
        last_index = term * len_a + index
        if (last_index >= len_a * b):
            print 0
            return
        indexes.append(last_index)

    single_cycle = last_index + 1
    if (single_cycle % len_a == 0):
        print len_a * b / (single_cycle * d)
    else:
        one_round = single_cycle % len_a
        rounds = one_round * d + 1
        print 1 + (b - rounds) / (rounds - 1)

solve()

rd = lambda : map(int, raw_input().split())
rep1, rep2 = rd()
s1 = raw_input()
s2 = raw_input()
for ch in s2:
  if not ch in s1:
    print 0
    exit()

d = {}
i = 0
j = 0
c1 = 1
c2 = 0
cicle_key = 0, 0
while True:
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1
  if (i, j) in d:
    cicle_key = (i, j)
    break
  d[(i, j)] = (c1, c2)
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1

rep1 -= d[cicle_key][0]
cicles_left = rep1 / (c1 - d[cicle_key][0])
c2 += cicles_left * (c2 - d[cicle_key][1])
rep1 -= cicles_left * (c1 - d[cicle_key][0])

i, j = cicle_key
c1 = 0
while True:
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1

rd = lambda : map(int, raw_input().split())
rep1, rep2 = rd()
s1 = raw_input()
s2 = raw_input()
for ch in s2:
  if not ch in s1:
    print 0
    exit()

d = {}
i = 0
j = 0
c1 = 1
c2 = 0
cicle_key = 0, 0
while True:
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1
  print (i, j), '->', (c1, c2)
  if (i, j) in d:
    cicle_key = (i, j)
    break
  d[(i, j)] = (c1, c2)
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1

rep1 -= d[cicle_key][0]
cicles_left = rep1 / (c1 - d[cicle_key][0])
c2 += cicles_left * (c2 - d[cicle_key][1])
rep1 -= cicles_left * (c1 - d[cicle_key][0])

i, j = cicle_key
c1 = 0
while True:
  i += 1
  j += 1
  if j == len(s2): j = 0
  if i == len(s1):
    i = 0
    c1 += 1
  while s1[i] != s2[j]:
    i += 1
    if i == len(s1):
      i = 0
      c1 += 1
  if c1 > rep1:
    print c2 / rep2
    exit()
  if j == len(s2) - 1: c2 += 1