#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
const double eps = 1e-9;
using namespace std;
char a[MAXN], c[MAXN];
long long dp[MAXN][40];
long long n, m, b, d;
int solve() {
  for (long long i = 0; i < n; i++) {
    long long cur = i;
    for (long long j = 0; j < m; j++) {
      long long cnt = 0;
      while (cnt <= n && a[cur % n] != c[j]) cur++, cnt++;
      if (a[cur % n] != c[j]) return 0;
      cur++;
    }
    dp[i][0] = cur - i;
  }
  for (long long j = 1; j < 40; j++)
    for (long long i = 0; i < n; i++)
      dp[i][j] = dp[(dp[i][j - 1] + i) % n][j - 1] + dp[i][j - 1];
  return 1;
}
long long ans() {
  long long cur = 0, ret = 0;
  for (long long i = 39; i >= 0; i--)
    if (dp[cur % n][i] + cur <= b * n) {
      cur += dp[cur % n][i];
      ret += (1ll << i);
    }
  return ret;
}
int main() {
  scanf("%I64d", &(b)), scanf("%I64d", &(d));
  scanf("%s %s", a, c);
  n = strlen(a), m = strlen(c);
  if (!solve())
    printf("%d\n", (0));
  else
    printf("%I64d\n", (ans() / d));
  return 0;
}
