#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string a, b;
int da, db;
typedef long long LL;
LL getnum(string s, int d)
{
int ans = 0;
for (int i = 0; i < s.length(); i++)
{
if (d == s[i] - '0')ans = ans * 10 + s[i] - '0';
}
return ans;
}
int main()
{
cin >> a >> da >> b >> db;
LL aa = getnum(a, da);
LL bb = getnum(b, db);
printf("%lld", aa + bb);
return 0;
}