#include <bits/stdc++.h>
int a, b;
char s[105], t[105], la, lb;
int next[105], add[105], num[105];
int cnt, tm;
int mod[105];
int ans;
int temp;
int DFS(int now) {
  if (next[now] != -1) {
    temp = num[now];
    a -= num[now];
    cnt -= num[now];
    tm -= add[now];
    return 0;
  }
  num[now] = cnt;
  cnt++;
  int more = 0;
  int ptr = now;
  for (int i = 0; i < la; i++) {
    if (ptr == lb) ptr = 0, more++;
    if (s[i] == t[ptr]) ptr++;
  }
  if (ptr == lb) ptr = 0, more++;
  next[now] = ptr;
  if (next[ptr] == -1) add[ptr] = more;
  tm += more;
  mod[cnt] = tm;
  return DFS(ptr);
}
int main() {
  scanf("%d%d%s%s", &a, &b, s, t);
  la = strlen(s), lb = strlen(t);
  memset(next, -1, sizeof next);
  cnt = 0, tm = 0, mod[0] = 0, add[0] = 0;
  DFS(0);
  int A = a / cnt, B = a % cnt;
  ans += A * tm + mod[B + temp];
  printf("%d\n", ans / b);
  return 0;
}
