#include <bits/stdc++.h>
using namespace std;
int go[111];
int m, n;
int f(int i) { return (i + go[i % m]) % m; }
struct F {
  int s;
  F(int _s) : s(_s) {}
  int operator()() {
    int k = go[s % m];
    s += k;
    return k;
  }
  int operator!=(const F& f) { return s % m != f.s % m; }
};
pair<int, int> floyd(int x0) {
  F tortoise(x0);
  F hare(x0);
  tortoise();
  hare();
  hare();
  while (tortoise != hare) {
    tortoise();
    hare();
    hare();
  }
  int mu = 0;
  tortoise = F(x0);
  while (tortoise != hare) {
    tortoise();
    hare();
    ++mu;
  }
  int lambda = 1;
  hare = tortoise;
  hare();
  while (hare != tortoise) {
    hare();
    lambda++;
  }
  return make_pair(lambda, mu);
}
int main() {
  ios_base::sync_with_stdio(false);
  int b, d;
  string a, c;
  cin >> b >> d >> a >> c;
  n = a.size();
  m = c.size();
  for (int _n(m), i(0); i < _n; i++) {
    int k = 0;
    for (int _n(n), j(0); j < _n; j++)
      if (a[j] == c[(i + k) % m]) k++;
    go[i] = k;
  }
  int p = 0;
  if (0) {
    for (int _n(b), i(0); i < _n; i++) {
      int k = go[p % m];
      p += k;
    }
  }
  p = 0;
  if (1) {
    int p1 = 0;
    pair<int, int> ret = floyd(p1);
    int mu = ret.second;
    int cycle_length = ret.first;
    for (int _n(min(mu, b)), i(0); i < _n; i++) {
      p1 = go[p % m];
      p += p1;
    }
    if (b > mu) {
      b -= mu;
      int div = b / cycle_length;
      int rem = b % cycle_length;
      int cnt_div = 0, cnt_rem = 0;
      int pp = p;
      for (int _n(cycle_length), i(0); i < _n; i++) {
        if (i == b) break;
        p1 = go[pp % m];
        cnt_div += p1;
        if (i < rem) cnt_rem += p1;
        pp += p1;
      }
      p += div * cnt_div + cnt_rem;
    }
  }
  cout << p / m / d << endl;
  return 0;
}
