//* Problem  : 2675.   Kickdown 
//* Contest  : acm.tju.edu.cn/toj
//* Type     : Solution
//* Date     : 2008.08.01
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

typedef pair <int,int> PIII;
typedef vector <int> VI;
typedef vector <vector<int> > VVI;
typedef vector <pair<int,int> > VPII;
typedef vector <vector<pair<int,int> > > VVPII;

#define int64 long long
#define PI (2.0 * acos(0.0))
#define MP make_pair
#define PB push_back
#define SZ(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORSZ(i, a) FOR(i, SZ(a))
#define FORE(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= int(b); i--)
#define INF 1000000000
#define INFL 1000000000000000000LL
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

inline int si(){int tt; scanf("%d", &tt); return tt;}

char s1[300], s2[300];

int res;

int solve(char *s1, char *s2)
{
	int n1 = strlen(s1);
	int n2 = strlen(s2);
	int res = INF;
	for (int sh = 0; sh <= n2; sh++)
	{
		int f = 1;
		for (int i = 0; s1[i] && s2[i+sh]; i++)
			if (s1[i] == '2' && s2[i+sh] == '2')
			{
				f = 0; break;
			}
		if (f)
		{
			res = max(n1 + sh, n2);
			return res;
		}
	}
	return res;
}

void result()
{
	printf("%d\n", res);
}

int main()
{
#ifdef _DEBUG
	freopen("1064", "r", stdin);
#endif
	scanf("%s %s", s1, s2);
	res = min(solve(s1, s2), solve(s2, s1));
	result();
	return 0;
}

