#include <bits/stdc++.h>
using namespace std;
int T;
const int maxn = 1e4 + 7;
int n, m;
string s, t;
int to[maxn];
void solve() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
  memset(to, -1, sizeof(to));
  for (int i = (0); i < (n); ++i)
    if (s[i] != '.') {
      int pre = 0;
      to[i] = -1;
      for (int j = (i); j < (n); ++j) {
        pre += s[j] == '.' ? -1 : 1;
        if (pre == 0) {
          to[i] = j;
          break;
        }
      }
    }
  int INF = 101010;
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));
  dp[0][0] = 0;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m + 1); ++j) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      if (j < m && s[i] == t[j])
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
      if (s[i] != '.' && to[i] != -1)
        dp[to[i] + 1][j] = min(dp[to[i] + 1][j], dp[i][j]);
    }
  cout << dp[n][m] << endl;
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
