//#undef LOCAL #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,N) for(int i=0;i<(int)(N);i++) #define rep1(i,N) for(int i=1;i<=(int)(N);i++) #define fs first #define sc second #define eb emplace_back #define pb eb #define all(x) x.begin(),x.end() template void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } #ifdef LOCAL #define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif template ostream& operator<<(ostream& os, const pair& p) { return os << "P(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os, const V& v) { os << "["; for (auto d : v) os << d << ", "; return os << "]"; } // cin.tie(nullptr); // ios::sync_with_stdio(false); // cout << fixed << setprecision(20); //境界iを中心とする最長回文の長さ/2 template V manacher(const S& s) { int n = int(s.size()); V r(n); if (n == 0) return r; r[0] = 1; for (int i = 1, j = 0; i < n; i++) { int& k = r[i]; k = (j + r[j] <= i) ? 0 : min(j + r[j] - i, r[2 * j - i]); while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) k++; if (j + r[j] < i + r[i]) j = i; } return r; } //文字iを中心とする最長回文の長さ template V manacher_even(const S& s) { int n = int(s.size()); V r(n + 1); for (int i = 1, j = 0; i < n; i++) { int& k = r[i]; k = (j + r[j] <= i) ? 0 : min(j + r[j] - i, r[2 * j - i]); while (0 <= i - 1 - k && i + k < n && s[i - 1 - k] == s[i + k]) k++; if (j + r[j] < i + r[i]) j = i; } return r; } int main() { int N,M;cin>>N>>M; string S,T;cin>>S>>T; bool bl=M%2==0; for(int m=0;m man=manacher_even(T),pal(M+1); for(int m=0;m=cur){ ans=min(ans,cnt+1); break; } if(cur<=pal[cur/2]*2){ break; } cur=pal[cur/2]*2; cnt+=1; } reverse(S.begin(),S.end()); } } } } if(ans==inf){ ans=-1; } cout<