#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
string a, b, c , d;
int ans = 0;

void parse(){
	for(auto&u:c){
		if(u>='0' && u <='9'){
			int ile = u-'0';
			for(int i = 0 ; i < ile; i++){
				a.pb('*');
			}
			ans++;
		}
		else{
			a.pb(u);
		}
	}
	for(auto&u:d){
		if(u>='0' && u <='9'){
			int ile = u-'0';
			for(int i = 0 ; i < ile; i++){
				b.pb('*');
			}
			ans++;
		}
		else{
			b.pb(u);
		}
	}
}

int dp[11001][2001];

int lcs(){
	for(int i = 1; i <= sz(a); i++){
		for(int j = 1; j <= sz(b); j++){
			if(a[i-1] == '*' || b[j-1] == '*' || a[i-1] == b[j-1]){
				dp[i][j] = dp[i-1][j-1] +1;
			}
			else{
				dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
			}
		}
	}
	return dp[sz(a)][sz(b)];
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> c >> d;
	parse();
	//cout << a << '\n' << b << endl;
	//cout << ans << endl;
	
	cout <<ans + sz(a) + sz(b) - 2*lcs() << '\n'; 
	return 0;
}