#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
string up, down;
int repeat1, repeat2;
bool vis[MAXN + 5];
pair<int, int> counts[MAXN + 5];
pair<int, int> start, ending;
bool valid() {
  int upmask = 0, downmask = 0;
  for (int c = 0; c < up.size(); c++) upmask |= (1 << (up[c] - 'a'));
  for (int c = 0; c < down.size(); c++) downmask |= (1 << (down[c] - 'a'));
  return (downmask & upmask) == downmask;
}
pair<int, int> simulate(int j = 0) {
  memset(vis, 0, sizeof(vis));
  memset(counts, 0, sizeof(counts));
  int i = 0;
  int cnt1 = 0, cnt2 = j;
  while (repeat1 > 0 && i < up.size()) {
    if (down[j] == up[i]) {
      j++, j %= down.size();
      cnt2++;
    }
    cnt1++;
    if (i + 1 == up.size()) {
      repeat1--;
      if (vis[j]) break;
      vis[j] = true;
      counts[j] = make_pair(cnt1, cnt2);
    }
    i++, i %= up.size();
  }
  start = counts[j];
  ending = make_pair(cnt1, cnt2);
  return make_pair((cnt1 - counts[j].first) / up.size(),
                   (cnt2 - counts[j].second) / down.size());
}
int main() {
  int c, c2;
  cin >> repeat1 >> repeat2 >> up >> down;
  if (!valid())
    printf("0\n");
  else {
    int ret;
    pair<int, int> repeat = simulate();
    ret = ending.second / down.size();
    if (repeat1) {
      int blocks = repeat1 / repeat.first;
      int rem = repeat1 % repeat.first;
      ret += blocks * repeat.second;
      repeat1 = rem;
      if (repeat1) {
        simulate(ending.second % down.size());
        ret += ending.second / down.size();
      }
    }
    printf("%d\n", ret / repeat2);
  }
  return 0;
}
