#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const long long oo = 1LL << 60;
const long long kNumMoves = 4;
const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
int b, d;
string a, c;
int GetValue() {
  int aLen = a.size();
  int cLen = c.size();
  vector<int> f(cLen, 0);
  for (int i = 0; i < int(cLen); ++i)
    for (int j = 0; j < int(aLen); ++j) {
      if (a[j] == c[(i + f[i]) % cLen]) ++f[i];
    }
  int res = 0;
  for (int i = 0; i < int(b); ++i) res += f[res % cLen];
  res /= d;
  res /= cLen;
  return res;
}
int main() {
  cin >> b >> d;
  cin >> a >> c;
  cout << GetValue();
  int i;
  cin >> i;
  return 0;
}
