#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 1e9 + 10, MOD = 1e9 + 7, Sq = 708;
const long long INF = 1e18 + 10;
int f[110], t[110], s[110];
int main() {
  ios_base::sync_with_stdio(false);
  int b, d;
  string a, c;
  cin >> b >> d;
  cin >> a >> c;
  int j = 0, ans = 0, ans1, pos = 0, ans2 = 0;
  for (int k = 0; k < a.length() * b; k++) {
    if (k / a.length() > c.length() && ans == 0) {
      cout << 0;
      return 0;
    }
    int i = (k % a.length());
    if (a[i] == c[j]) {
      j++;
      if (j == c.length()) {
        j = 0, ans++, t[i]++;
        if (t[i] > 1) {
          ans1 = k - f[i];
          ans2 = ans - s[i];
          pos = k;
          break;
        } else
          f[i] = k, s[i] = ans;
      }
    }
  }
  j = 0;
  int l = (a.length() * b - pos - 1) / ans1;
  if (pos) {
    ans += l * ans2;
    for (int k = pos + l * ans1 + 1; k < a.length() * b; k++) {
      int i = (k % a.length());
      if (a[i] == c[j]) {
        j++;
        if (j == c.length()) j = 0, ans++;
      }
    }
  }
  cout << ans / d;
  return 0;
}
