using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Danica
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Unesite broj X: ");
            int X = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Unesite broj Y: ");
            int Y = Convert.ToInt32(Console.ReadLine());
            int brOdX = 1;
            int brOdY = 1;
            int tempX = 0;
            int tempY = 0;
            int A = 0;
            bool nullCheck = false;

            Console.WriteLine();
            tempX = X;
            while (X > 9)
            {
                X = X / 10;
                brOdX++;
            }
            X = tempX;

            tempY = Y;
            while (Y > 9)
            {
                Y = Y / 10;
                brOdY++;
            }
            Y = tempY;

            tempX = 0;
            tempY = 0;
            for (int i = 1; i < (brOdX + 1) || i < (brOdY + 1); i++)
            {
                tempX = X % 10;
                tempY = Y % 10;

                if (X == tempX || Y == tempY)
                {
                    if (X == tempX && Y == tempY)
                    {

                    }
                    else
                    {
                        nullCheck = true;
                    }
                }
                    if (tempX > tempY)
                    {
                        A += Convert.ToInt32(tempX * Math.Pow(10, i));
                    }
                    if (tempX < tempY)
                    {
                        A += Convert.ToInt32(tempY * Math.Pow(10, i));
                    }
                    if (tempX == tempY)
                    {
                        if (nullCheck == false)
                        {
                            A += Convert.ToInt32(tempX * Math.Pow(10, i));
                            i++;
                            A += Convert.ToInt32(tempX * Math.Pow(10, i));
                            brOdX++;
                            brOdY++;
                        }
                        else
                        {
                            A += Convert.ToInt32(tempX * Math.Pow(10, i));
                        }
                    }
                    X /= 10;
                    Y /= 10;
                }
            A /= 10;

            Console.WriteLine("Novodobijeni sudareni broj je: " + (A));

            Console.ReadLine();
        }
    }
}