#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
pair<int, int> f[MAXN];
int vis[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  long long b, d;
  cin >> b >> d;
  string a, c;
  cin >> a >> c;
  int n = a.size(), m = c.size();
  for (int i = 0; i < m; i++) {
    int s = i;
    for (int j = 0; j < n; j++) {
      if (c[s] == a[j]) s++;
      if (s == m) {
        f[i].first++;
        s = 0;
      }
    }
    f[i].second = s;
  }
  long long cycsum = 0, cyclen = 0;
  int p = 0, tostart = 0;
  do {
    vis[p] = true;
    p = f[p].second;
    tostart++;
  } while (!vis[p]);
  int start = p;
  do {
    cyclen++;
    cycsum += f[p].first;
    p = f[p].second;
  } while (p != start);
  if (start == 0) tostart = 0;
  long long ans = 0;
  p = 0;
  for (int i = 0; i < min((long long)tostart, b); i++) {
    ans += f[p].first;
    p = f[p].second;
  }
  b -= min((long long)tostart, b);
  ans += cycsum * (b / cyclen);
  p = start;
  for (int i = 0; i < b % cyclen; i++) {
    ans += f[p].first;
    p = f[p].second;
  }
  cout << ans / d;
}
