#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, dp[105], nxt[105];
char a[105], b[105];
signed main() {
  scanf("%d%d", &n, &m);
  scanf("%s%s", a, b);
  int lena = strlen(a);
  int lenb = strlen(b);
  memset(dp, 0, sizeof(dp));
  memset(nxt, 0, sizeof(nxt));
  for (int i = 0; i < lenb; i++) {
    int now = i;
    for (int j = 0; j < lena; j++) {
      if (a[j] == b[now]) {
        now++;
      }
      if (now == lenb) {
        dp[i]++;
        now = 0;
      }
    }
    nxt[i] = now;
  }
  int ans = 0;
  int now = 0;
  for (int i = 0; i < n; i++) {
    ans += dp[now];
    now = nxt[now];
  }
  printf("%d", ans / m);
  return 0;
}
