#include <bits/stdc++.h>
const int N = 100010;
const int M = 400010;
using namespace std;
int n, m;
int lena, lenb;
char a[N], b[N];
int nxt[N], cnt[N];
void SOLVE() {
  int ans = 0;
  for (int i = 1; i <= lenb; i++) {
    cnt[i] = 0;
    nxt[i] = i;
    for (int j = 1; j <= lena; j++) {
      if (a[j] == b[nxt[i]]) {
        nxt[i]++;
        if (nxt[i] == lenb + 1) cnt[i]++, nxt[i] = 1;
      }
    }
  }
  int now = 1;
  for (int i = 1; i <= n; i++) {
    ans += cnt[now];
    now = nxt[now];
  }
  printf("%d\n", ans / m);
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s%s", a + 1, b + 1);
  lena = strlen(a + 1);
  lenb = strlen(b + 1);
  SOLVE();
  return 0;
}
