#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 200001;
const int inf = 1e9 + 7;
int dp[N][2];
int br1[26], br2[26];

void solve() {
    string t, s;
    int n, m;
    cin >> t >> s;
    n = t.size();
    m = s.size();
    for (int i = 0; i < n; i++) {
        br1[t[i] - 'a']++;
        dp[i + 1][0] = br1[s[0] - 'a'];
    }
    for (int i = 0; i < m; i++)
        br2[s[i] - 'a']++;
    if (br2[0] == m) {
        cout << max(br1[0] - br2[0] + 1, 0) << endl;
        return;
    }
    for (int j = 1; j < m; j++) {
        for (int i = 1; i <= n; i++) {
            if (t[i - 1] == s[j])
                dp[i][1] = min(dp[i][0], dp[i - 1][1] + 1);
            else
                dp[i][1] = dp[i - 1][1];
        }
        for (int i = 1; i <= n; i++) {
            swap(dp[i][1], dp[i][0]);
        }
    }
    cout << dp[n][0];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}