#include <bits/stdc++.h>
using namespace std;
const int mod = 1000002013, maxn = 1006;
long long INF = 100000000000ll;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int l[maxn], p[maxn];
long long walk[maxn][35];
int from[maxn];
int main() {
  int t, af, n, k, b, d;
  string a, c;
  cin >> b >> d;
  cin >> a >> c;
  int now = 0;
  long long full = 0, hom = 0, periodfull = 0, periodhom = 0;
  for (int i = 0; i < a.size(); ++i) {
    int hom = 0, vhom;
    for (int j = 0; j < c.size(); ++j) {
      vhom = hom;
      while (c[j] != a[(i + hom) % a.size()]) {
        ++hom;
        if (hom - vhom > a.size()) {
          cout << "0\n";
          return 0;
        }
      }
      ++hom;
    }
    walk[i][0] = hom;
  }
  for (int i = 1; i < 35; ++i)
    for (int j = 0; j < a.size(); ++j) {
      walk[j][i] = min(
          INF, walk[j][i - 1] + walk[(j + walk[j][i - 1]) % a.size()][i - 1]);
    }
  long long where = 0, ov = a.size() * (b + 0ll), hm = 0;
  while (1) {
    int good = 0;
    for (int i = 30; i >= 0; --i)
      if (walk[where][i] <= ov) {
        hm += (1ll << i);
        ov -= walk[where][i];
        where = (where + walk[where][i]) % a.size();
        good = 1;
      }
    if (!good) break;
  }
  cout << hm / d << endl;
}
