#include <bits/stdc++.h>
using namespace std;
string a, b;
pair<long long, long long> dp[110];
void hek(int S) {
  int save = S;
  bool ki = 0;
  int c1 = 0;
  for (int i = (0); i < int(a.size()); i += 1) {
    if (a[i] == b[S]) S++, ki = 1;
    if (S == b.size()) S = 0, c1++;
  }
  if (!ki)
    dp[save] = make_pair(-1, -1);
  else
    dp[save] = make_pair(c1, S);
}
void moz(pair<int, int> &A) {
  if (A.second == b.size()) A.first++, A.second = 0;
}
int main() {
  long long c1, c2;
  cin >> c1 >> c2 >> a >> b;
  for (int i = (0); i < int(b.size()); i += 1) hek(i);
  long long S = 0, c = 0;
  while (c1--) {
    pair<int, int> tt = dp[S];
    if (tt.first == -1) break;
    c += tt.first;
    S = tt.second;
  }
  c /= c2;
  cout << c << endl;
  return 0;
}
