using System;
public class Program
{
public static void Main()
int x, y,z;
bool flag = false;
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
z = ((x % 10 * 10) + (x / 10 % 10));
while ( y > 0 )
if ((y % 100) == x || ((y % 100) == z)) flag = true;
y = (y / 10);
}
Console.WriteLine(flag);