#include <bits/stdc++.h>
using namespace std;
int n, m, v[110];
long long dp[110][110], lp, pre, b, d, len, E, D;
long long p[110], q[110];
char a[110], c[110];
long long find(int x, int y) {
  int nx = (x + 1) >= n ? 0 : x + 1;
  int ny = (y + 1) >= m ? 0 : y + 1;
  if (a[x] == c[y]) return dp[x][y] = (ny ? 1 + find(nx, ny) : 1);
  return dp[x][y] = 1 + find(nx, y);
}
int main() {
  int ok;
  memset(dp, -1, sizeof(dp));
  memset(p, -1, sizeof(p));
  scanf("%d%d%s%s", &b, &d, a, c);
  n = strlen(a);
  m = strlen(c);
  for (int i = (0); i < (m); i++) {
    ok = 0;
    for (int j = (0); j < (n); j++)
      if (a[j] == c[i]) {
        ok = 1;
        break;
      }
    if (!ok) {
      puts("0");
      return 0;
    }
  }
  long long cur = 0, A = b, B = 0;
  ok = 1;
  A *= n;
  while (cur < A) {
    int x = cur % n;
    if (p[x] == -1) {
      p[x] = cur;
      q[x] = B;
      cur += find(x, 0);
      if (cur <= A) B++;
    } else {
      long long t = (A - cur) / (cur - p[x]);
      if (t) {
        cur += t * (cur - p[x]);
        B += t * (B - q[x]);
      } else
        p[x] = -1;
    }
  }
  cout << B / d << endl;
  return 0;
}
