#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int inf = 0x3f3f3f3f;
int b, d;
string a, c;
int dp[110][110];
int dfs(int A, int C) {
  if (A >= a.size()) return 0;
  int &ret = dp[A][C];
  if (ret + 1) return ret;
  ret = 0;
  for (int i = A; i < a.size(); i++)
    if (a[i] == c[C]) ret = max(ret, dfs(i + 1, (C + 1) % c.size()) + 1);
  return ret;
}
int main() {
  cin >> b >> d;
  cin >> a >> c;
  memset(dp, -1, sizeof(dp));
  long long ret = 0;
  for (int i = 0, j = 0; i < b; i++) {
    int len = dfs(0, j);
    ret += len;
    j = (len + j) % c.size();
  }
  ret = ret / c.size();
  ret = ret / d;
  cout << ret << endl;
  return 0;
}
