#include <bits/stdc++.h>
using namespace std;
long long b, d;
string a, c;
map<long long, long long> need[150];
int main() {
  cin >> b >> d;
  cin >> a >> c;
  string h = "";
  long long ans = 0;
  long long sizea = a.size();
  long long sizec = c.size();
  for (int i = 0; i < sizec; i++) {
    int s = 0;
    for (int j = 0; j < sizea; j++)
      if (c[i] == a[j]) s = 1;
    if (s == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < sizea; i++) {
    int now = 0;
    for (long long j = i; now < sizec; j++)
      if (a[j % sizea] == c[now]) {
        now++;
        need[i][1] = j - i + 1;
      }
  }
  for (long long i = 2; i <= 2ll * b * sizea; i *= 2ll)
    for (long long j = 0; j < sizea; j++)
      need[j][i] =
          need[j][i / 2ll] + need[(j + need[j][i / 2ll]) % sizea][i / 2ll];
  long long now = 0;
  long long tot = b * sizea;
  long long time = 0;
  while (tot >= need[now][1])
    for (long long i = 1;; i *= 2ll)
      if (need[now][i] > tot) {
        i /= 2ll;
        tot -= need[now][i];
        now += need[now][i];
        now %= sizea;
        time += i;
        break;
      }
  cout << time / d << endl;
}
