#include <bits/stdc++.h>
using namespace std;
char s1[110], s2[110];
int a, c, b, d;
pair<int, int> dis[110][110];
bool check(char ch) {
  for (int i = 0; i < a; i++)
    if (s1[i] == ch) return true;
  return false;
}
int next(int w, char ch) {
  while (1) {
    w++;
    if (w == a) w = 0;
    if (s1[w] == ch) return w;
  }
}
int cal() {
  for (int i = 0; i < c; i++)
    if (!check(s2[i])) return 0;
  memset(dis, -1, sizeof(dis));
  int i = 0, j = next(-1, s2[0]), last;
  int g = 1, h = 1;
  while (dis[i][j] == make_pair(-1, -1)) {
    dis[i][j] = make_pair(g, h);
    i++;
    if (i == c) {
      i = 0;
      g++;
    }
    last = j;
    j = next(last, s2[i]);
    if (j <= last) {
      h++;
      if (h > b) return g - 1;
    }
  }
  int ans = g - 1;
  b -= h;
  int k = b / (h - dis[i][j].second);
  ans += k * (g - dis[i][j].first);
  b %= h - dis[i][j].second;
  b++;
  while (1) {
    i++;
    if (i == c) {
      i = 0;
      ans++;
    }
    last = j;
    j = next(last, s2[i]);
    if (j <= last) {
      b--;
      if (b == 0) break;
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s%s", s1, s2);
  a = strlen(s1), c = strlen(s2);
  int k = cal();
  printf("%d\n", k / d);
  return 0;
}
