#include <bits/stdc++.h>
using namespace std;
string a, b;
int fa, fb, la, lb;
int al[26], bl[26], mark[105], res[105];
int search(int pos) {
  int j = 0;
  while (1) {
    if (a[pos % la] == b[j])
      pos++, j++;
    else
      pos++;
    if (j == lb) return pos;
  }
}
int main() {
  cin >> fa >> fb;
  cin >> a >> b;
  la = a.length();
  lb = b.length();
  for (int i = 0; i < la; i++) al[a[i] - 'a']++;
  for (int i = 0; i < lb; i++) bl[b[i] - 'a']++;
  for (int i = 0; i < 26; i++)
    if (al[i] * fa < bl[i]) {
      cout << "0" << endl;
      return 0;
    }
  int pos = 0;
  memset(mark, -1, sizeof(mark));
  int ln = la * fa, cycleln, cl, cd = 0;
  while (1) {
    mark[pos % la] = pos;
    pos = search(pos);
    if (pos > ln) break;
    cd++;
    if (mark[pos % la] != -1) {
      cycleln = pos - mark[pos % la];
      cl = cd - res[pos % la];
      break;
    }
    res[pos % la] = cd;
  }
  int rest = ln - pos;
  if (rest > 0) {
    cd = cd + ((rest / cycleln) * cl);
    pos = pos + (rest / cycleln) * cycleln;
    rest = rest % cycleln;
    while (1) {
      pos = search(pos);
      if (pos > ln) break;
      cd++;
    }
  }
  cout << cd / fb << endl;
  return 0;
}
