import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int infinity = int.max / 2;
immutable int NA = -1;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto t = readln.strip;
		auto k = s.length.to !(int);
		auto n = t.length.to !(int);

		auto p = new int [k];
		p[] = NA;
		int [] stack;
		foreach (j; 0..k)
		{
			if (s[j] == '.')
			{
				if (!stack.empty)
				{
					p[j] = stack.back;
					stack.popBack ();
					stack.assumeSafeAppend ();
				}
			}
			else
			{
				stack ~= j;
			}
		}

		auto f = new int [] [] (2, k + 1);
		int b = 0;
		f[b][0] = 0;
		foreach (j; 1..k + 1)
		{
			f[b][j] = f[b][j - 1] + 1;
			if (p[j - 1] != NA)
			{
				f[b][j] = min (f[b][j], f[b][p[j - 1]]);
			}
		}
		foreach (i; 0..n)
		{
			b ^= 1;
			f[b][] = infinity;
			foreach (j; i + 1..k + 1)
			{
				f[b][j] = f[b][j - 1] + 1;
				if (t[i] == s[j - 1])
				{
					f[b][j] = min (f[b][j], f[!b][j - 1]);
				}
				if (p[j - 1] != NA)
				{
					f[b][j] = min (f[b][j], f[b][p[j - 1]]);
				}
			}
		}
		writeln (f[b][k]);
	}
}
