#include <bits/stdc++.h>
using namespace std;
string a, c;
long long int sz1, sz2, b, d, vis[105], cnt1[105], cnt2[105], cnt3[105], res;
int main() {
  cin >> b >> d >> a >> c;
  long long int temp1 = 0, temp2 = 0, j = 0, k = 0, is = 0;
  sz1 = a.size(), sz2 = c.size();
  for (long long int i = 0; i < sz1; i++) cnt3[a[i] - 'a']++;
  for (long long int j = 0; j < sz2; j++)
    if (!cnt3[c[j] - 'a']) {
      cout << "0\n";
      return 0;
    }
  while (true) {
    k %= sz2;
    j %= sz1;
    if (!j) temp2++, is = (k != 0);
    if (a[j] == c[k]) {
      if (vis[j] && k == 0) {
        long long int x = temp2 - cnt2[j];
        long long int y = temp1 - cnt1[j];
        if (is)
          res = cnt1[j], b -= cnt2[j] - 1;
        else
          res = 0;
        res += ((b - is) * y) / x;
        if (is) {
          long long int e = 0, z = 0;
          for (long long int w = j; w < sz1; w++) {
            if (c[e] == a[w]) e++;
            if (e == sz2) z++, e = 0;
          }
          res += z;
        }
        cout << res / d << '\n';
        return 0;
      } else if (k == 0) {
        vis[j] = 1;
        cnt1[j] = temp1;
        cnt2[j] = temp2;
        temp1++;
      }
      k++;
      is = 1;
    }
    j++;
  }
}
