using System;
public class Program
{
public static void Main()
int x,i=1;
bool flag = true;
for ( i = 1; i <= 10;i++ )
x = int.Parse(Console.ReadLine());
while (x != 0)
if (x >= 10000 || x < 0) flag = false;
if ((x % 10) != 2 && (x % 10) != 6 && (x % 10) != 9) flag = false;
x = x / 10;
}
Console.WriteLine(flag);