#include <bits/stdc++.h>
using namespace std;
int Count[105];
int Next[105];
int main() {
  int b, d;
  cin >> b >> d;
  string S1, S2;
  cin >> S1 >> S2;
  int x;
  for (int n = 0; n < S2.size(); ++n) {
    Count[n] = 0;
    x = n;
    for (int m = 0; m < S1.size(); ++m) {
      if (S2[x] == S1[m]) {
        ++x;
        if (x == S2.size()) {
          Count[n]++;
          x = 0;
        }
      }
    }
    Next[n] = x;
  }
  long long Ans = 0;
  x = 0;
  for (int n = 0; n < b; ++n) {
    Ans += Count[x];
    x = Next[x];
  }
  Ans /= (long long)d;
  cout << Ans << endl;
  return 0;
}
