#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << ' ' << *it << " = " << a;
  err(++it, args...);
}
const long long MOD = 1e9 + 7;
const int N = 1e6 + 9, M = (1 << 31), OO = 0x3f3f3f3f;
char s[N], t[N];
int pos[30];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  int n = strlen(s + 1), m = strlen(t + 1), l = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    if (pos[s[i] - 'a'] == 0) pos[s[i] - 'a'] = i;
  sort(s + 1, s + 1 + n);
  for (int i = 1; i <= m; ++i) {
    int r = lower_bound(s + 1, s + n + 1, t[i]) - s;
    if (r == n + 1 || r == 0 || s[r] != t[i]) {
      ans = -1;
      break;
    } else {
      r = pos[t[i] - 'a'];
      if (l > r)
        ans += (n - l) + r;
      else
        ans += r - l;
      l = r;
    }
  }
  printf("%lld", ans);
  return 0;
}
