#include <bits/stdc++.h>
using namespace std;
int t1, t2;
string s1, s2;
int pre[1100];
int main() {
  cin >> t1 >> t2 >> s1 >> s2;
  set<char> S;
  long long len1 = s1.length();
  long long len2 = s2.length();
  for (int i = 0; i < len1; i++) S.insert(s1[i]);
  for (int i = 0; i < len2; i++)
    if (S.find(s2[i]) == S.end()) {
      printf("0\n");
      return 0;
    }
  S.clear();
  for (int i = 0; i < len2; i++) S.insert(s2[i]);
  if ((int)S.size() == 1) {
    long long cont = 0;
    for (int i = 0; i < len1; i++)
      if (s2[0] == s1[i]) cont++;
    cont *= t1;
    cout << cont / len2 / t2 << endl;
    return 0;
  }
  for (int id = 0; id < len1; id++) {
    int ii = id, i = id, j = 0;
    while (j < len2) {
      if (i >= len1) i = 0;
      if (s1[i] == s2[j]) {
        i++, ii++, j++;
      } else {
        i++, ii++;
      }
    }
    pre[id] = ii - id;
  }
  long long ii = 0, jj = 0, resp = 0;
  int i = 0, j = 0;
  int cont;
  for (cont = 0; 1; cont++) {
    int id = i % len1;
    if (i + pre[id] > len1 * t1) break;
    i += pre[id];
  }
  cout << cont / t2 << endl;
  return 0;
}
