#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000009;
const double eps = 1.0e-9;
const unsigned long long MAX_N = 4001;
int nums[MAX_N];
map<char, vector<int> > strPos;
vector<map<char, int> > nextTable;
set<char> patSet;
struct Pack {
  Pack(int eNum = 0, int p = 0) : eleNum(eNum), pos(p){};
  int eleNum, pos;
};
vector<Pack> strInfo;
bool buildTable(string& str, string& pat) {
  nextTable.resize(str.size());
  for (unsigned int i = 0; i < (unsigned long long)(str.size()); ++i) {
    strPos[str[i]].push_back(i);
  }
  for (unsigned int i = 0; i < (unsigned long long)(pat.size()); ++i) {
    patSet.insert(pat[i]);
  }
  set<char>::iterator iter;
  for (iter = patSet.begin(); iter != patSet.end(); iter++) {
    vector<int>& pos = strPos[*iter];
    if (pos.empty()) return false;
    int index = 0;
    for (unsigned int i = 0; i < (unsigned long long)(str.size()); ++i) {
      if (index == pos.size()) {
        nextTable[i][*iter] = -1;
      } else if (i < pos[index]) {
        nextTable[i][*iter] = pos[index];
      } else if (i == pos[index]) {
        nextTable[i][*iter] = pos[index];
        index++;
      }
    }
  }
  return true;
}
Pack getInfo(string& str, string& pat, int start) {
  int eleNum = 0, pos = start;
  for (unsigned int i = 0; i < (unsigned long long)(pat.size()); ++i) {
    pos = nextTable[pos][pat[i]];
    if (pos == -1) {
      pos = nextTable[0][pat[i]];
      eleNum++;
    }
    pos++;
    if (pos == str.size()) {
      eleNum++;
      pos = 0;
    }
  }
  bool isFind = false;
  for (unsigned int i = (unsigned long long)(pos);
       i < (unsigned long long)(str.size()); i++) {
    if (pat[0] == str[i]) {
      pos = i;
      isFind = true;
      break;
    }
  }
  if (!isFind) {
    pos = 0;
    eleNum++;
  }
  return Pack(eleNum, pos);
}
void buildInfo(string& str, string& pat) {
  strInfo.resize(str.size());
  for (unsigned int i = 0; i < (unsigned long long)(str.size()); ++i) {
    strInfo[i] = getInfo(str, pat, i);
  }
}
int main(int argc, char** argv) {
  std::ios::sync_with_stdio(false);
  long long b, d;
  cin >> b >> d;
  string str, pat;
  cin >> str >> pat;
  if (buildTable(str, pat)) {
    buildInfo(str, pat);
    Pack t;
    int pos = 0, num = 0, q = 0, remain = b;
    bool isFirst = true;
    while (true) {
      t = strInfo[pos];
      remain -= t.eleNum;
      if (remain > 0) {
        pos = t.pos;
        num++;
        if (num == d) {
          num = 0;
          q++;
        }
      } else if (remain == 0 && t.pos == 0) {
        num++;
        if (num == d) {
          num = 0;
          q++;
        }
        break;
      } else {
        break;
      }
      if (pos == 0 && num == 0) {
        int strNum, patNum;
        strNum = b - remain;
        patNum = q;
        q = q * (b / strNum);
        remain = b % strNum;
      }
    }
    cout << q << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
