#include <bits/stdc++.h>
using namespace std;
const int MAXL = 150, MAXN = 1001;
char a[MAXL], b[MAXL];
long long p1, p2;
long long step[MAXL][MAXN];
long long go[MAXL][MAXN];
long long getstart(int pos) {
  int l = strlen(b), la = strlen(a);
  long long res = 0;
  for (int i = pos, j = 0; j < l; ++i, ++res)
    if (a[i % la] == b[j]) ++j;
  return res;
}
int main() {
  cin >> p1 >> p2;
  cin >> a >> b;
  int la = strlen(a), lb = strlen(b);
  for (int j = 0; j < lb; ++j) {
    bool fl = true;
    for (int i = 0; i < la; ++i)
      if (b[j] == a[i]) {
        fl = false;
        break;
      }
    if (fl) {
      printf("0\n");
      return 0;
    }
  }
  for (int i = 0; i < la; ++i) {
    step[i][0] = getstart(i);
  }
  for (int i = 1; (1 << i) <= p2; ++i)
    for (int j = 0; j < la; ++j)
      step[j][i] = step[(j + step[j][i - 1]) % la][i - 1] + step[j][i - 1];
  for (int j = 0; j < la; ++j) {
    go[j][0] = 0;
    for (int t = p2, i = 0, pos = j; t; t >>= 1, ++i) {
      if (t & 1) {
        go[j][0] += step[pos][i];
        pos += step[pos][i];
        pos %= la;
      }
    }
  }
  long long ans = 0;
  for (int i = 1;; ++i) {
    for (int j = 0; j < la; ++j)
      go[j][i] = go[(j + go[j][i - 1]) % la][i - 1] + go[j][i - 1];
    if (go[0][i] > la * p1) {
      long long pos = 0, len = 0;
      while (--i >= 0) {
        if (go[pos][i] + len <= la * p1) {
          len += go[pos][i];
          ans += (1 << i);
          pos += go[pos][i];
          pos %= la;
        }
      }
      break;
    }
  }
  cout << ans;
  return 0;
}
