#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int findMinTime(const string& S, const string& T) {
int n = S.length();
int m = T.length();
unordered_map<char, vector<int>> charPositions;
for (int i = 0; i < n; ++i) {
charPositions[S[i]].push_back(i);
}
int currentPos = -1;
int totalTime = 0;
for (int i = 0; i < m; ++i) {
char targetChar = T[i];
if (charPositions.find(targetChar) == charPositions.end()) {
return -1;
}
vector<int>& positions = charPositions[targetChar];
int minTime = INT_MAX;
for (int pos : positions) {
int time = abs(pos - currentPos);
if (currentPos == -1) {
time = 0;
}
minTime = min(minTime, time);
}
if (minTime == INT_MAX) {
return -1;
}
totalTime += minTime;
currentPos = positions[0];
for (int j = 1; j < positions.size(); ++j) {
if (abs(positions[j] - currentPos) < abs(positions[currentPos] - currentPos)) {
currentPos = positions[j];
}
}
}
return totalTime;
}
int main() {
int n, m;
cin >> n >> m;
string S, T;
cin >> S >> T;
int result = findMinTime(S, T);
cout << result << endl;
return 0;
}