#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
char a[N+5],b[N+5];
int main()
{
scanf("%s%s",a,b);
if(strcmp(a,b)==0)
printf("-1\n");
else
{
printf("%d\n",max(strlen(a),strlen(b)));
}
return 0;
}