#include <bits/stdc++.h>
using namespace std;
char s[10005], t[10005];
int dp[2][10005];
int nt[10005];
int main() {
  scanf("%s", s);
  scanf("%s", t);
  int n = strlen(s);
  int m = strlen(t);
  for (int i = 0; i < n; i++) {
    int sum = 0;
    nt[i] = -1;
    for (int j = i; j < n; j++) {
      if (s[j] == '.')
        sum--;
      else
        sum++;
      if (sum < 0) break;
      if (sum == 0) {
        nt[i] = j + 1;
        break;
      }
    }
  }
  int c = 0;
  for (int j = 0; j <= n; j++) dp[c][j] = 1e9;
  dp[c][0] = 0;
  for (int i = 0; i <= m; i++) {
    for (int j = i; j <= n; j++) dp[c ^ 1][j] = 1e9;
    for (int j = i; j < n; j++) {
      if (i < m && j < n && t[i] == s[j])
        dp[c ^ 1][j + 1] = min(dp[c ^ 1][j + 1], dp[c][j]);
      dp[c][j + 1] = min(dp[c][j + 1], dp[c][j] + 1);
      if (nt[j] != -1) dp[c][nt[j]] = min(dp[c][nt[j]], dp[c][j]);
    }
    c ^= 1;
  }
  printf("%d\n", dp[c ^ 1][n]);
}
