#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXSIZE 11
int main(void)
{
char A[2][MAXSIZE], D[2][MAXSIZE], P[2][MAXSIZE] = {0};
if (scanf("%s %s %s %s", A[0], D[0], A[1], D[1]) != 4)
return 0;
unsigned int sum = 0;
char *ptr[2];
for (unsigned int i = 0; i != 2; i++)
{
ptr[i] = A[i];
while (*ptr[i] != '\0')
{
if (strncmp(ptr[i], D[i], 1) == 0)
strncat(P[i], D[i], 1);
++ptr[i];
}
sum += atoi(P[i]);
}
printf("%u\n", sum);
return 0;
}