#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const int INF = 1000 * 1000 * 1000;
const long long INF64 = sqr(static_cast<long long>(INF));
const double PI = acos(-1.0);
const int N = 110;
int b, d;
string a, c;
int u[N], v[N];
int n, m;
bool visited[N];
vector<int> lpos[256];
int main() {
  cin >> b >> d >> a >> c;
  n = (int)a.length();
  m = (int)c.length();
  for (int i = 0; i < n; ++i) lpos[a[i]].push_back(i);
  int q = 0;
  for (int pos = 0; pos < n * b;) {
    if (visited[pos % n]) {
      int k = (n * b - pos) / (pos - u[pos % n]);
      q += (q - v[pos % n]) * k;
      pos += k * (pos - u[pos % n]);
    }
    u[pos % n] = pos;
    v[pos % n] = q;
    visited[pos % n] = true;
    for (int i = 0; i < m; ++i) {
      int npos = -1;
      for (int j = 0; j < (int)lpos[c[i]].size(); ++j) {
        int p = (pos / n) * n + lpos[c[i]][j] + 1;
        if (p <= pos) p += n;
        assert(p > pos);
        if (p <= n * b && (npos == -1 || npos > p)) npos = p;
      }
      if (npos == -1) {
        cout << q / d << endl;
        return 0;
      } else
        pos = npos;
    }
    ++q;
  }
  cout << q / d << endl;
  return 0;
}
