// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
#define maxL 150000
// mylittlepony
using namespace std;
pair<string,string> makeR(int seed) {
srand(seed);
int N =rand()%maxL+1, M =rand()%maxL+1;
pair<string,string> ret;
char c[] ="URL12";
int d =0;
for(int i =0; i < N; i++) {
int x =rand()%5;
while(x == 0 && d == 0) x =rand()%5;
while(d == 0 && x <= 2) x =rand()%5;
if(x > 2) d++;
if(x == 0) d--;
ret.ff +=c[x];}
d =0;
for(int i =0; i < M; i++) {
int x =rand()%5;
while(x == 0 && d == 0) x =rand()%5;
while(d == 0 && x <= 2) x =rand()%5;
if(x > 2) d++;
if(x == 0) d--;
ret.ss +=c[x];}
return ret;}
int bruteforce(string s, string t) {
vector< vector<int> > G(5000);
for(int i =1; i <= 2000; i++) {
G[2*i+1].push_back(i);
G[2*i].push_back(i);
G[i].push_back(2*i);
G[i].push_back(2*i+1);
int a =i+1;
while(a%2 == 0) a /=2;
if(a != 1) {
G[i].push_back(i+1);
G[i+1].push_back(i);}}
int a =1, b =1;
for(int i =0; i < s.length(); i++) {
if(s[i] == 'U') a /=2;
if(s[i] == '1') a =2*a;
if(s[i] == '2') a =2*a+1;
if(s[i] == 'L') a--;
if(s[i] == 'R') a++;}
for(int i =0; i < t.length(); i++) {
if(t[i] == 'U') b /=2;
if(t[i] == '1') b =2*b;
if(t[i] == '2') b =2*b+1;
if(t[i] == 'L') b--;
if(t[i] == 'R') b++;}
queue<int> q; q.push(a);
if(a < 0 || b < 0) return -1;
vector<int> dist(5000,1000000);
dist[a] =0;
while(!q.empty()) {
for(int i =0; i < G[q.front()].size(); i++) if(dist[G[q.front()][i]] > dist[q.front()]+1) {
dist[G[q.front()][i]] =dist[q.front()]+1;
q.push(G[q.front()][i]);}
q.pop();}
return dist[b];}
int solve(string s, string t) {
// do pekneho tvaru
stack< pair<int,int> > A;
stack< pair<int,int> > B;
int dA =0, dB =0;
for(int i =0; i < s.length(); i++) {
if(s[i] == 'U') {
dA--;
if(A.empty()) return -1;
pair<int,int> p =A.top(); A.pop();
p.ss--;
if(p.ss > 0) A.push(p);}
if(s[i] == '1') { dA++;
if(A.empty() || A.top().ff == 1) {A.push(make_pair(0,1)); continue;}
pair<int,int> p =A.top(); A.pop();
p.ss++;
A.push(p);}
if(s[i] == '2') { dA++;
if(A.empty() || A.top().ff == 0) {A.push(make_pair(1,1)); continue;}
pair<int,int> p =A.top(); A.pop();
p.ss++;
A.push(p);}
if(s[i] == 'R') {
if(A.empty()) return -1;
pair<int,int> p =A.top(); A.pop();
if(p.ff == 0) {
p.ss--; if(p.ss > 0) {A.push(p);
A.push(make_pair(1,1));}
else {
if(A.empty()) A.push(make_pair(1,1));
else A.top().ss++;}
continue;}
if(A.empty()) return -1;
p.ff =0;
pair<int,int> r =A.top(); A.pop();
r.ss--;
if(r.ss > 0) {
A.push(r);
A.push(make_pair(1,1));
A.push(p);
continue;}
if(!A.empty()) A.top().ss++;
else A.push(make_pair(1,1));
A.push(p);}
if(s[i] == 'L') {
if(A.empty()) return -1;
pair<int,int> p =A.top(); A.pop();
if(p.ff == 1) {
p.ss--; if(p.ss > 0) {A.push(p);
A.push(make_pair(0,1));}
else {
if(A.empty()) A.push(make_pair(0,1));
else A.top().ss++;}
continue;}
if(A.empty()) return -1;
p.ff =1;
pair<int,int> r =A.top(); A.pop();
r.ss--;
if(r.ss > 0) {
A.push(r);
A.push(make_pair(0,1));
A.push(p);
continue;}
if(!A.empty()) A.top().ss++;
else A.push(make_pair(0,1));
A.push(p);}}
for(int i =0; i < t.length(); i++) {
if(t[i] == 'U') { dB--;
if(B.empty()) return -1;
pair<int,int> p =B.top(); B.pop();
p.ss--;
if(p.ss > 0) B.push(p);}
if(t[i] == '1') { dB++;
if(B.empty() || B.top().ff == 1) {B.push(make_pair(0,1)); continue;}
pair<int,int> p =B.top(); B.pop();
p.ss++;
B.push(p);}
if(t[i] == '2') { dB++;
if(B.empty() || B.top().ff == 0) {B.push(make_pair(1,1)); continue;}
pair<int,int> p =B.top(); B.pop();
p.ss++;
B.push(p);}
if(t[i] == 'R') {
if(B.empty()) return -1;
pair<int,int> p =B.top(); B.pop();
if(p.ff == 0) {
p.ss--; if(p.ss > 0) {B.push(p);
B.push(make_pair(1,1));}
else {
if(B.empty()) B.push(make_pair(1,1));
else B.top().ss++;}
continue;}
if(B.empty()) return -1;
p.ff =0;
pair<int,int> r =B.top(); B.pop();
r.ss--;
if(r.ss > 0) {
B.push(r);
B.push(make_pair(1,1));
B.push(p);
continue;}
if(!B.empty()) B.top().ss++;
else B.push(make_pair(1,1));
B.push(p);}
if(t[i] == 'L') {
if(B.empty()) return -1;
pair<int,int> p =B.top(); B.pop();
if(p.ff == 1) {
p.ss--; if(p.ss > 0) {B.push(p);
B.push(make_pair(0,1));}
else {
if(B.empty()) B.push(make_pair(0,1));
else B.top().ss++;}
continue;}
if(B.empty()) return -1;
p.ff =1;
pair<int,int> r =B.top(); B.pop();
r.ss--;
if(r.ss > 0) {
B.push(r);
B.push(make_pair(0,1));
B.push(p);
continue;}
if(!B.empty()) B.top().ss++;
else B.push(make_pair(0,1));
B.push(p);}}
if(dA > dB) {swap(A,B); swap(dA,dB);}
int D =0, ans =100000;
while(dA < dB) {
D++, dB--;
pair<int,int> p =B.top(); B.pop();
p.ss--; if(p.ss > 0) B.push(p);}
vector<int> Va,Vb;
while(!A.empty()) {
pair<int,int> p =A.top(); A.pop();
for(int i =0; i < p.ss; i++) Va.push_back(p.ff);}
while(!B.empty()) {
pair<int,int> p =B.top(); B.pop();
for(int i =0; i < p.ss; i++) Vb.push_back(p.ff);}
/* ALL_THE(Va,it) cout << *it;
cout << ".\n";
ALL_THE(Vb,it) cout << *it;
cout << ".\n";
*/
int d =0;
ans =2*Va.size();
for(int i =0; i < Va.size(); i++) {
d =2*d+Va[Va.size()-1-i]-Vb[Vb.size()-1-i];
if(abs(d) > 100000000) break;
ans =min(ans,2*((int)Va.size()-1-i)+abs(d));}
return ans+D;}
int main() {
cin.sync_with_stdio(0);
srand(time(0));
string s,t;
cin >> s >> t;
// cout << bruteforce(s,t) << "\n";
cout << solve(s,t) << "\n";
/* for(int i =0; i < 100; i++) {
pair<string,string> s =makeR(rand()%10000000);
// if(bruteforce(s.ff,s.ss) != solve(s.ff,s.ss) && solve(s.ff,s.ss) != -1)
// cout << s.ff << " " << s.ss << endl;
if(solve(s.ff,s.ss) != -1) cout << "." << endl;}
*/ return 0;}
// look at my code
// my code is amazing