Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.Your task is to print the radixes of all numeral system which can contain the time "a:b".

The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.

Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.

NoteLet's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var input = Read();
            var index = input.IndexOf(":");
            var h = input.Substring(0, index);
            var m = input.Substring(index + 1);
            var hInt = GetInts(h);
            var mInt = GetInts(m);
            var maxH = hInt.Max();
            var maxM = mInt.Max();
            if(hInt.Count == 1 && mInt.Count == 1)
            {
                if(hInt[0] > 23)
                    Console.WriteLine(0);
                else
                {
                    Console.WriteLine(-1);
                }
            }
            else
            {
                var i = 0;
                for (i = 59; i > 1; i--)
                {
                    if(i <= maxH || i <= maxM)
                    {
                        i = -1;
                        break;
                    }
                    var hT = GetN(i, hInt);
                    var mT = GetN(i, mInt);
                    if(hT <=23 && mT <=59 && hT >= 0 && mT >= 0)
                        break;
                }
                if(i<=1)
                {
                    Console.WriteLine(0);
                    return;
                }
                var res = new StringBuilder();
                for (int j = Math.Max(2, Math.Max(maxH, maxM) + 1); j <= i; j++)
                {
                    res.Append(j + " ");
                }
                Console.WriteLine(res.ToString().TrimEnd());
            }
        }

        private static long GetN(int t, List<int> ints)
        {
            long res = 0;
            for (int i = 0; i < ints.Count; i++)
            {
                res *= t;
                res += ints[i];
                if (res > 60)
                    return res;
            }
            return res;
        }

        private static List<int> GetInts(string s)
        {
            var res = new List<int>();

            for (int i = 0; i < s.Length; i++)
            {
                if(s[i] == '0' && res.Count == 0)
                    continue;

                if(char.IsLetter(s[i]))
                {
                    res.Add((s[i] - 'A') + 10);
                }
                else
                {
                    res.Add(s[i] - '0');
                }
            }

            if(res.Count == 0)
                res.Add(0);

            return res;

        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace AcmSolution4
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader("../../../a.txt"));
#endif

            string s = GetStr();
            var ss = s.Split(':');
            string a = ss[0], b = ss[1];

            while (a.Length > 1 && a[0] == '0')
                a = a.Substring(1);

            while (b.Length > 1 && b[0] == '0')
                b = b.Substring(1);

            var aa = new List<int>();
            var bb = new List<int>();
            foreach (char c in a)
            {
                if (char.IsDigit(c))
                    aa.Add(c - '0');
                else
                    aa.Add(c - 'A' + 10);
            }

            foreach (char c in b)
            {
                if (char.IsDigit(c))
                    bb.Add(c - '0');
                else
                    bb.Add(c - 'A' + 10);
            }

            int[] min = {0};
            aa.ForEach(x => min[0] = Math.Max(x, min[0]));
            bb.ForEach(x => min[0] = Math.Max(x, min[0]));

            ++min[0];

            int max = 0;
            bool good = true;

            for (int Base = min[0]; good && Base < 70; ++Base)
            {
                int t = 1;
                int res = 0;
                for (int i = aa.Count - 1; good && i >= 0; --i)
                {
                    if (i != aa.Count - 1) t *= Base;
                    res += aa[i]*t;
                    if (res > 23) good = false;
                }
                if (good)
                    max = Base;
            }

            int max2 = 0;
            if (max >= min[0])
            {
                good = true;
                for (int Base = min[0]; good && Base < 70; ++Base)
                {
                    int t = 1;
                    int res = 0;
                    for (int i = bb.Count - 1; good && i >= 0; --i)
                    {
                        if (i != bb.Count - 1) t *= Base;
                        res += bb[i]*t;
                        if (res > 59) good = false;
                    }
                    if (good)
                        max2 = Base;
                }
            }

            max = Math.Min(max, max2);

            if (max > 60)
                WL("-1");
            else if (max < min[0])
                WL("0");
            else for (int i = min[0]; i <= max; ++i)
                W(i + " ");
        }

        static int GetInt()
        {
            return int.Parse(GetStr());
        }

        static int GetInt(string s)
        {
            return int.Parse(s);
        }

        static int[] GetInts()
        {
            string[] ss = GetStrs();
            int[] nums = new int[ss.Length];

            int i = 0;
            foreach (string s in ss)
                nums[i++] = GetInt(s);

            return nums;
        }

        static string[] GetStrs()
        {
            return Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static long GetLong()
        {
            return long.Parse(GetStr());
        }

        static string GetStr()
        {
            return Console.ReadLine();
        }

        static void WL<T>(T s)
        {
            Console.WriteLine(s);
        }

        static void W<T>(T s)
        {
            Console.Write(s);
        }
    }

    internal class Pair
    {
        public int number;
        public int value;
        public Pair(int i, int j)
        {
            number = i;
            value = j;
        }
    }
}

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

namespace MarsClock
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split(':');
            if (check(tokens[0], 23, 100) && check(tokens[1], 59, 100))
            {
                Console.WriteLine("-1");
                return;
            }
            bool prn = false;
            for (int i = 2; i <= 100; ++i)
                if (check(tokens[0], 23, i) && check(tokens[1], 59, i))
                {
                    Console.Write(i.ToString() + " ");
                    prn = true;
                }
            if (prn == false)
                Console.WriteLine("0");
        }
        static bool check(string chk, int maxim, int ba)
        {
            long total = 0;
            for (int i = 0; i < chk.Length; ++i)
            {
                int C;
                if (chk[i] >= '0' && chk[i] <= '9')
                    C = chk[i] - '0'; // Используются коды символов, вычитая символ ноль получим число
                else if (chk[i] >= 'A' && chk[i] <= 'Z')
                    C = chk[i] - 'A' + 10; //А тут вычитая А получим число и потом прибавляем 10
                else
                    return false;
                if (C >= ba)
                    return false;
                total *= ba;
                total += C;
                if (total > maxim)
                    return false;
            }
            return true;
        }
    }
}

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

namespace B
{
    class Program
    {
        static int intFromStrBase(string s, int b)
        {
            int[] a = s.Select(c => c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'Z' ? c - 'A' + 10 : 999).ToArray();
            if (a.Any(x => x >= b))
                return -1;

            int sum = 0;
            for (int i = 0; i < a.Length; i++)
            {
                sum = sum * b + a[i];
                if (sum > 60)
                    return -1;
            }

            return sum;
        }

        static bool possible(string h, string m, int b)
        {
            int ih = intFromStrBase(h, b);
            int im = intFromStrBase(m, b);
            return (ih >= 0 && ih <= 23 && im >= 0 && im <= 59);
        }

        static void Main(string[] args)
        {
            string[] hm = Console.ReadLine().Split(':');
            while (hm[0].Length > 1 && hm[0].StartsWith("0"))
                hm[0] = hm[0].Substring(1);
            while (hm[1].Length > 1 && hm[1].StartsWith("0"))
                hm[1] = hm[1].Substring(1);

            List<int> poss = new List<int>();
            for (int i = 1; i <= 100; i++)
                if (possible(hm[0], hm[1], i))
                    poss.Add(i);

            if (possible(hm[0], hm[1], 99))
                Console.WriteLine(-1);
            else if(poss.Count == 0)
                Console.WriteLine(0);
            else
                foreach(var x in poss)
                    Console.Write("{0} ", x);

        }
    }
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hm = Console.ReadLine().Split(':');

            Func<string, int, int> s2i = (s, b) =>
            {
                var a = s.Select(c => (c <= '9') ? c - '0' : c - 'A' + 10).ToArray();
                if (a.Any(x => x >= b)) return 60;
                return a.Aggregate((acc, x) => acc < 60 ? acc * b + x : acc);
            };

            var possible = Enumerable.Range(1, 100).Where(x => s2i(hm[0], x) <= 23 && s2i(hm[1], x) <= 59).ToArray();

            if(!possible.Any())
                Console.WriteLine(0);
            else if(possible.Last() == 100)
                Console.WriteLine(-1);
            else
                foreach(var x in possible)
                    Console.Write("{0} ", x);
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

public class pB
{
  public static void Main ( )
  {
#if false
    Console.SetIn ( new StreamReader ( @"e:\zin.txt" ) );
#endif
    calc ( );
    //Console.WriteLine ( calc() );
  }

  private static int calc ( )
  {
    int z=0;
    string inp = Console.ReadLine ( );
    int cpos = inp.IndexOf ( ':' );
    string hr = inp.Substring ( 0, cpos );
    string min = inp.Substring ( cpos + 1 );
    char[] chr = hr.ToCharArray();
    char[] cmin = min.ToCharArray();
    for ( int i=0; i < chr.Length; i++ )
      if ( chr[i] != '0' )
        break;
      else
        chr[i] = ' ';
    for ( int i=0; i < cmin.Length; i++ )
      if ( cmin[i] != '0' )
        break;
      else
        cmin[i] = ' ';
    hr = new string ( chr );
    min = new string ( cmin );
    hr = hr.Trim ( );
    min = min.Trim ( );
    if ( hr == "" )
      hr = "0";
    if ( min == "" )
      min = "0";

    int minresh;
    int maxresh;
    int minresn;
    int maxresn;
    int mindigit;
    int maxdigit;
    //hr
    mindigit = 99;
    maxdigit = 0;
    for ( int i=0; i < hr.Length; i++ )
    {
      char c = hr[i];
      int val;
      if ( c >= 'A' )
        val = 10 + Convert.ToInt32 ( c ) - Convert.ToInt32 ( 'A' );
      else
        val = int.Parse ( c.ToString ( ) );

      mindigit = Math.Min ( mindigit, val );
      maxdigit = Math.Max ( maxdigit, val );
    }
    int minbase = maxdigit + 1;

    mindigit = 99;
    maxdigit = 0;
    for ( int i=0; i < min.Length; i++ )
    {
      char c = min[i];
      int val = ctoi ( c );
      mindigit = Math.Min ( mindigit, val );
      maxdigit = Math.Max ( maxdigit, val );
    }
    minbase = Math.Max ( minbase, maxdigit + 1 );

    bool infH=false;
    if ( hr.Length == 1 )
    {
      if ( ctoi(hr[0]) < 24 )
        infH = true;
    }
    bool infM=false;
    if ( min.Length == 1 )
    {
      if ( ctoi ( min[0] ) < 59 )
        infM = true;
    }
    if ( infH && infM )
    {
      Console.WriteLine(-1);
      return -1;
    }

    int bs = minbase;
    bool valid = true;
    while ( true )
    {
      int hrval=0;
      for ( int i=hr.Length - 1; i >= 0; i-- )
      {
        hrval += ctoi(hr[i]) * ( int ) Math.Pow ( bs, hr.Length - 1 - i );
      }
      int minval=0;
      for ( int i=min.Length - 1; i >= 0; i-- )
      {
        minval += ctoi ( min[i] ) * ( int ) Math.Pow ( bs, min.Length - 1 - i );
      }
      if ( minval > 59 || hrval > 23 )
        break;
      bs++;
    }
    int maxbase = bs-1;
    if ( maxbase < minbase )
    {
      Console.WriteLine ( "0" );
      return 0;
    }

    for ( int i=minbase; i <= maxbase; i++ )
    {
      Console.Write ( i );
      if ( i < maxbase )
        Console.Write ( " " );
    }

    return 0;
  }

  public static int ctoi ( char c )
  {
    int val;
    if ( c < 'A' )
      val = int.Parse ( c.ToString ( ) );
    else
      val = 10 + Convert.ToInt32 ( c ) - Convert.ToInt32 ( 'A' );
    return val;
  }

  public static int[] ReadLineToInts ( )
  {
    string line = Console.ReadLine ( );
    string[] arStrings = line.Split ( new char[] { ' ' } );

    int N = arStrings.Length;
    int[] ints = new int[N];
    for ( int i=0; i < N; i++ )
      ints[i] = int.Parse ( arStrings[i] );
    return ints;
  }

}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

public class EllysCheckers
{
    public static int [] time(string t)
    {
        int [] res = new int[t.Length];
        for (int i = 0; i < t.Length; i++) {

            if(t[t.Length - i - 1]>='A' && t[t.Length - i - 1] <= 'Z')
            {
                res[i] = (int)t[t.Length - i - 1] - 55;
            }
            else
            {
                res[i] = int.Parse(t[t.Length - i - 1].ToString());
            }
        }
        return res;

    }
    public static bool check(int[] t, int s, bool type )
    {
        int z = 1;
        int ans = 0;
        for (int i = 0; i < t.Length; i++) {
            if(t[i] >= s)
                return false;
            ans += t[i] * z;
            z *= s;
        }
        if(type)
            if(ans >= 24)
                return false;
            else
                return true;
        else
            if(ans >= 60)
                return false;
            else
                return true;
    }
    public static void Main(string[] args)
    {
        string []str = Console.ReadLine().Split(':').ToArray();
        string hour = str[0];
        string min = str[1];
        int [] h = time(hour);
        int [] m = time(min);
        if(check(h, 61, true) && check(m, 61, false))
        {
            Console.WriteLine (-1);
            return;
        }
        List<int> ans = new List<int>();
        for (int i = 2; i <=60; i++) {
            if(check(h, i, true) && check(m, i, false))
                ans.Add(i);
        }
        if(ans.Count == 0)
            Console.WriteLine (0);
        else
        {
            string pr = "";
            foreach (var item in ans) {
                Console.Write(pr + item);
                pr = " ";
            }
        }

    }

}

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private static readonly string NRange = new string(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' });

        private void Solve()
        {
            var s = io.NextLine().Split(':');

            s[0] = s[0].TrimStart('0');
            s[1] = s[1].TrimStart('0');

            var min = 0;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    min = Math.Max(min, NRange.IndexOf(s[i][j]));
                }
            }

            if (min > 0)
            {
                List<string> parts = new List<string>();

                var pch = -1;
                var pcm = -1;

                int i = min;

                do
                {
                    var ch = Calc10(s[0], i);
                    var cm = Calc10(s[1], i);

                    if (ch < 24 && cm < 60)
                    {
                        if (pch == ch && pcm == cm)
                        {
                            io.Print(-1);
                            return;
                        }

                        parts.Add((i + 1).ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        break;
                    }
                    pch = ch;
                    pcm = cm;

                } while (++i < 10000000);

                if (parts.Count > 0)
                {
                    io.Print(string.Join(" ", parts.ToArray()));
                    return;
                }
                io.Print(0);
                return;
            }

            io.Print(-1);
        }

        private int Calc10(string s, int min)
        {
            int res = 0;

            foreach (var c in s)
            {
                res *= (min + 1);
                res += NRange.IndexOf(c);
            }

            return res;

        }
    }

}

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

namespace ConsoleApplication5
{
    class Program
    {

        static void Main()
        {
            string[] vrem = Console.ReadLine().Split(':');
            char[] a = new char[5];
            char[] b = new char[5];
            int[] a1 = new int[5];
            int[] b1 = new int[5];

            for (int i = vrem[0].Length - 1; i >= 0; i--)
            {
                a[vrem[0].Length - 1 - i] = vrem[0][i];
                if (a[vrem[0].Length - 1 - i] >= 65 && a[vrem[0].Length - 1 - i] <= 90)
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 55);
                else
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 48);
            }
            for (int i = vrem[1].Length - 1; i >= 0; i--)
            {
                b[vrem[1].Length - 1 - i] = vrem[1][i];
                if (b[vrem[1].Length - 1 - i] >= 65 && b[vrem[1].Length - 1 - i] <= 90)
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 55);
                else
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 48);
            }

            int max = 0;
            for (int i = 0; i < a1.Length; i++)
            {
                if (max < a1[i])
                    max = a1[i];
                if (max < b1[i])
                    max = b1[i];
            }

            int[] otvet = new int[61];
            int k = max;

                double q = 0;
                double w = 0;
                while (k < 61)
                {
                    k++;
                    q = 0;
                    w = 0;
                    for (int i = a1.Length - 1; i >= 0; i--)
                        q = q + a1[i] * Math.Pow(k, i);

                    for (int i = b1.Length - 1; i >= 0; i--)
                        w = w + b1[i] * Math.Pow(k, i);

                    if (q <= 23 && w <= 59)
                        otvet[k-1] = k;
                    else
                        break;
                }

                if (k == 61)
                    Console.WriteLine("-1");
                else if (k == max + 1)
                    Console.WriteLine("0");
                else
                {
                    for (int i = 0; i < otvet.Length; i++)
                        if (otvet[i] != 0)
                            Console.Write(otvet[i] + " ");
                }

        }
    }
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFContest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    String[] buf = Console.ReadLine().Split(':');
                    String ret = "";
                    if (can(buf, 1024))
                    {
                        Console.WriteLine("-1");
                        continue;
                    }
                    for (int i = 2; i <= 1024; i++)
                    {
                        if (can(buf, i))
                        {
                            ret = ret + i + " ";
                        }
                    }
                    if (ret == "")
                        ret = "0";
                    Console.WriteLine(ret);
                }
            }
            catch (Exception)
            {
            }
        }

        private static bool can(string[] buf, int b)
        {
            long[] d = new long[2];
            for (int i = 0; i < 2; i++)
            {
                d[i] = 0;
                for (int j = 0; j < buf[i].Length; j++)
                {
                    int fd = buf[i][j] >= '0' && buf[i][j] <= '9' ? buf[i][j] - '0' : buf[i][j] - 'A' + 10;
                    if (fd >= b) return false;
                    d[i] = d[i] * b + fd;
                }
            }
            return d[0] >= 0 && d[0] <= 23 && d[1] >= 0 && d[1] <= 59;
        }
    }
}

using System;
using System.Collections;
namespace Iran
{
    class AmirGoharshady
    {
        static bool ok(string chk, int maxim, int ba)
        {
            long total = 0;
            for (int i = 0; i < chk.Length; ++i)
            {
                int C;
                if (chk[i] >= '0' && chk[i] <= '9')
                    C = chk[i] - '0';
                else if (chk[i] >= 'A' && chk[i] <= 'Z')
                    C = chk[i] - 'A' + 10;
                else
                    return false;
                if (C >= ba)
                    return false;
                total *= ba;
                total += C;
                if (total > maxim)
                    return false;
            }
            return true;
        }
        public static void Main()
        {
            string[] inp = Console.ReadLine().Split(':');
            if (ok(inp[0], 23, 100) && ok(inp[1], 59, 100))
            {
                Console.WriteLine("-1");
                return;
            }
            bool prn = false;
            for(int i=2;i<=100;++i)
                if (ok(inp[0], 23, i) && ok(inp[1], 59, i))
                {
                    Console.Write(i.ToString()+" ");
                    prn = true;
                }
            if (prn == false)
                Console.WriteLine("0");
        }
    }
}

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

public class B
{
    public partial class Myon
    {

        static void Main()
        {
            B p = new B();
            p.solve();
        }

    }

    public void solve()
    {
        string[] str = stringRead().Split(':');
        List<int> res = new List<int>();

        for (int i = 1; i < 70; i++)
        {
            if (!Check(str[0], i) || !Check(str[1], i))
                continue;
            int h = Sum(str[0], i);
            int m = Sum(str[1], i);
            if (h < 24 && m < 60)
                res.Add(i);
        }//for i

        foreach(int a in res)
            if (a > 60)
            {
                Console.WriteLine(-1);
                return;
            }

        if (res.Count == 0)
        {
            Console.WriteLine(0);
            return;
        }

        for (int i = 0; i < res.Count; i++)
        {
            Console.Write(res[i]);
            if(i!=res.Count-1)
                Console.Write(" ");
        }//for i
        Console.WriteLine();
    }

    int Sum(string str, int radix)
    {
        int res = 0;
        int mul = 1;
        for (int i = str.Length - 1; i >= 0; i--)
        {
            res += CharToInt(str[i] )* mul;
            mul *= radix;
        }//forrev i
        return res;
    }

    bool Check(string str, int radix)
    {
        for (int i = 0; i < str.Length; i++)
        {
            if (CharToInt(str[i]) >= radix)
                return false;
        }//for i
        return true;
    }

    public static int CharToInt(char c)
    {
        if ('0' <= c && c <= '9')
            return c - '0';
        if ('A' <= c && c <= 'Z')
            return c - 'A' + 10;
        return -1;
    }//CharToInt

    public static char IntToChar(int i)
    {
        return (char)(i + '0');
    }//IntToChar

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Codeforces
{
    class B
    {
        private static int V(char ch)
        {
            if (ch - '0' >= 0 && ch - '0' <= 9) return ch - '0';
            return ch - 'A' + 10;
        }

        private static int Convert(string s, int rad)
        {
            int v = 0;
            int m = 1;
            for (int i = s.Length - 1; i >=0 ; i--)
            {
                if (V(s[i]) >= rad) return -1;
                v += m * V(s[i]);
                m *= rad;
            }

            return v;
        }

        private static object Go()
        {
            string[] data = GetString().Split(':');
            string h = data[0];
            string m = data[1];

            List<string> sol = new List<string>();
            for (int rad = 2; rad < 61; rad++)
            {
                int hi = Convert(h, rad);
                int mi = Convert(m, rad);

                if (hi > -1 && mi > -1 && hi < 24 && mi < 60)
                {
                    sol.Add(rad.ToString());
                    if (rad == 60)
                    {
                        return -1;
                    }
                }
            }

            if (sol.Count == 0) return 0;

            return string.Join(" ", sol.ToArray());
        }

        #region Template

        public static void Main(string[] args)
        {
            object output = Go();
            if (output != null)
                Wl<string>(output.ToString());
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        public struct Tuple<T, K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;

class c106_p2
{
    static int digit(char ch)
    {
        if (ch <= '9') return ch - '0';
        else return (ch - 'A') + 10;
    }

    static int number(string num, int b)
    {
        int fact = 1;
        int res = 0;
        for (int i = num.Length - 1; i >= 0; i--)
        {
            res += fact * digit(num[i]);
            fact *= b;
        }
        return res;
    }

    static void Main()
    {
        //Console.SetIn(new StreamReader(new FileStream("../../in.txt", FileMode.Open)));
        //StreamWriter out_sw = new StreamWriter(new FileStream("../../out.txt", FileMode.Create));
        //Console.SetOut(out_sw);

        string time = Console.In.ReadLine();
        string[] ss = time.Split(new char[] { ':' });
        string h = ss[0].TrimStart(new char[] { '0' });
        if (h == "") h = "0";
        string m = ss[1].TrimStart(new char[] { '0' });
        if (m == "") m = "0";
        char[] dg = (h + m).ToCharArray();
        Array.Sort<char>(dg);
        char max = dg[dg.Length - 1];
        int fb = digit(max) + 1;
        if (fb == 1)
        {
            Console.Out.WriteLine("-1");
            return;
        }
        if (h.Length == 1 && m.Length == 1)
        {
            if (digit(h[0]) <= 23 && digit(m[0]) <= 59)
            {
                Console.Out.WriteLine("-1");
                return;
            }
        }

        if (number(h, fb) > 23 || number(m, fb) > 59)
        {
            Console.Out.WriteLine("0");
            return;
        }

        for (int b = fb; ; b++)
        {
            if (number(h, b) > 23 || number(m, b) > 59) break;
            else Console.Out.WriteLine(b + " ");
        }

        Console.Out.WriteLine();
        //out_sw.Close();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp2
{
	class Program
	{
		static int dgt(char c)
		{
			if ('0' <= c && c <= '9')
			{
				return c - '0';
			}
			return 10 + c - 'A';
		}

		static int to_num(string s, int n)
		{
			int num = 0;
			int k = 1;
			for (int i = 1; i <= s.Length; i++)
			{
				num += dgt(s[s.Length - i]) * k;
				k *= n;
			}
			return num;
		}
		static bool fit(string s1, string s2, int n)
		{
			return to_num(s1, n) < 24 && to_num(s2, n) < 60;
		}

		static int get_min(string s)
		{
			int min = 0;
			for (int i = 0; i < s.Length; i++)
			{
				if (dgt(s[i]) > min)
				{
					min = dgt(s[i]);
				}
			}
			return min;
		}

		static void Main(string[] args)
		{
			string input = Console.ReadLine();
			var times = input.Split(':');
			int min = Math.Max(get_min(times[0]), get_min(times[1])) + 1;

			if (fit(times[0], times[1], 60))
			{
				Console.WriteLine(-1);
			}
			else
			{
				int i;
				for (i = min; i <= 59; i++)
				{
					if (!fit(times[0], times[1], i))
						break;
					Console.Write("{0} ", i);
				}
				if (i == min)
					Console.WriteLine(0);
			}
		}
	}
}

using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Martian_Clock
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(':');

            int min = Math.Max(2, 1+Math.Max(ss[0].Max(t => Code(t)), ss[1].Max(t => Code(t))));

            int h = Convert(ss[0], min);
            int m = Convert(ss[1], min);

            if (h > 23 || m > 59)
                writer.WriteLine("0");
            else if (h < min && m < min)
                writer.WriteLine("-1");
            else
            {
                for (int i = min;; i++)
                {
                    h = Convert(ss[0], i);
                    m = Convert(ss[1], i);

                    if (h <= 23 && m <= 59)
                    {
                        writer.Write(i);
                        writer.Write(' ');
                    }
                    else break;
                }
            }

            writer.Flush();
        }

        private static int Code(char t)
        {
            return t <= '9' ? t - '0' :10 + (t - 'A');
        }

        private static int Convert(string s, int r)
        {
            int ans = 0;

            for (int i = 0; i < s.Length; i++)
            {
                ans = ans*r + Code(s[i]);
            }

            return ans;
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            if (GetDecimal(hours, initbase, chars) >= 24 || GetDecimal(minutes, initbase, chars) >= 60)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var input = Read();
            var index = input.IndexOf(":");
            var h = input.Substring(0, index);
            var m = input.Substring(index + 1);
            var hInt = GetInts(h);
            var mInt = GetInts(m);
            var maxH = hInt.Max();
            var maxM = mInt.Max();
            if(hInt.Count == 1 && mInt.Count == 1)
            {
                if(hInt[0] > 23)
                    Console.WriteLine(0);
                else
                {
                    Console.WriteLine(-1);
                }
            }
            else
            {
                var i = 0;
                for (i = 24; i > 1; i--)
                {
                    if(i <= maxH || i <= maxM)
                    {
                        i = -1;
                        break;
                    }
                    var hT = GetN(i, hInt);
                    var mT = GetN(i, mInt);
                    if(hT <=23 && mT <=59)
                        break;
                }
                if(i<=1)
                {
                    Console.WriteLine(0);
                    return;
                }
                var res = new StringBuilder();
                for (int j = Math.Max(maxH, maxM) + 1; j <= i; j++)
                {
                    res.Append(j + " ");
                }
                Console.WriteLine(res.ToString().TrimEnd());
            }
        }

        private static long GetN(int t, List<int> ints)
        {
            long res = 0;
            for (int i = 0; i < ints.Count; i++)
            {
                res *= t;
                res += ints[i];
            }
            return res;
        }

        private static List<int> GetInts(string s)
        {
            var res = new List<int>();

            for (int i = 0; i < s.Length; i++)
            {
                if(s[i] == '0' && res.Count == 0)
                    continue;

                if(char.IsLetter(s[i]))
                {
                    res.Add((s[i] - 'A') + 10);
                }
                else
                {
                    res.Add(s[i] - '0');
                }
            }

            if(res.Count == 0)
                res.Add(0);

            return res;

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var input = Read();
            var index = input.IndexOf(":");
            var h = input.Substring(0, index);
            var m = input.Substring(index + 1);
            var hInt = GetInts(h);
            var mInt = GetInts(m);
            var maxH = hInt.Max();
            var maxM = mInt.Max();
            if(hInt.Count == 1 && mInt.Count == 1)
            {
                if(hInt[0] > 23)
                    Console.WriteLine(0);
                else
                {
                    Console.WriteLine(-1);
                }
            }
            else
            {
                var i = 0;
                for (i = 24; i > 1; i--)
                {
                    if(i <= maxH || i <= maxM)
                    {
                        i = -1;
                        break;
                    }
                    var hT = GetN(i, hInt);
                    var mT = GetN(i, mInt);
                    if(hT <=23 && mT <=59)
                        break;
                }
                if(i<=1)
                {
                    Console.WriteLine(0);
                    return;
                }
                var res = new StringBuilder();
                for (int j = 2; j <= i; j++)
                {
                    res.Append(j + " ");
                }
                Console.WriteLine(res.ToString().TrimEnd());
            }
        }

        private static long GetN(int t, List<int> ints)
        {
            long res = 0;
            for (int i = 0; i < ints.Count; i++)
            {
                res *= t;
                res += ints[i];
            }
            return res;
        }

        private static List<int> GetInts(string s)
        {
            var res = new List<int>();

            for (int i = 0; i < s.Length; i++)
            {
                if(s[i] == '0' && res.Count == 0)
                    continue;

                if(char.IsLetter(s[i]))
                {
                    res.Add((s[i] - 'A') + 10);
                }
                else
                {
                    res.Add(s[i] - '0');
                }
            }

            if(res.Count == 0)
                res.Add(0);

            return res;

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var input = Read();
            var index = input.IndexOf(":");
            var h = input.Substring(0, index);
            var m = input.Substring(index + 1);
            var hInt = GetInts(h);
            var mInt = GetInts(m);
            var maxH = hInt.Max();
            var maxM = mInt.Max();
            if(hInt.Count == 1 && mInt.Count == 1)
            {
                if(hInt[0] > 23)
                    Console.WriteLine(0);
                else
                {
                    Console.WriteLine(-1);
                }
            }
            else
            {
                var i = 0;
                for (i = 24; i > 1; i--)
                {
                    if(i <= maxH || i <= maxM)
                    {
                        i = -1;
                        break;
                    }
                    var hT = GetN(i, hInt);
                    var mT = GetN(i, mInt);
                    if(hT <=23 && mT <=59)
                        break;
                }
                if(i<=1)
                {
                    Console.WriteLine(0);
                    return;
                }
                var res = new StringBuilder();
                for (int j = Math.Max(2, Math.Max(maxH, maxM) + 1); j <= i; j++)
                {
                    res.Append(j + " ");
                }
                Console.WriteLine(res.ToString().TrimEnd());
            }
        }

        private static long GetN(int t, List<int> ints)
        {
            long res = 0;
            for (int i = 0; i < ints.Count; i++)
            {
                res *= t;
                res += ints[i];
                if (res > 60)
                    return res;
            }
            return res;
        }

        private static List<int> GetInts(string s)
        {
            var res = new List<int>();

            for (int i = 0; i < s.Length; i++)
            {
                if(s[i] == '0' && res.Count == 0)
                    continue;

                if(char.IsLetter(s[i]))
                {
                    res.Add((s[i] - 'A') + 10);
                }
                else
                {
                    res.Add(s[i] - '0');
                }
            }

            if(res.Count == 0)
                res.Add(0);

            return res;

        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private static readonly string NRange = new string(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' });

        private void Solve()
        {
            var s = io.NextLine().Split(':');

            s[0] = s[0].TrimStart('0');
            s[1] = s[1].TrimStart('0');

            var min = 0;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    min = Math.Max(min, NRange.IndexOf(s[i][j]));
                }
            }

            if (min > 0)
            {
                List<string> parts = new List<string>();

                var pch = -1;
                var pcm = -1;

                for (int i = min; i < NRange.Length; i++)
                {
                    var ch = Calc10(s[0], i);
                    var cm = Calc10(s[1], i);

                    if (ch < 24 && cm < 60)
                    {
                        if (pch == ch && pcm == cm)
                        {
                            io.Print(-1);
                            return;
                        }

                        parts.Add((i + 1).ToString(CultureInfo.InvariantCulture));
                    }
                    pch = ch;
                    pcm = cm;
                }

                if (parts.Count > 0)
                {
                    io.Print(string.Join(" ", parts.ToArray()));
                    return;
                }
                io.Print(0);
            }

            io.Print(-1);
        }

        private int Calc10(string s, int min)
        {
            int res = 0;

            foreach (var c in s)
            {
                res *= (min + 1);
                res += NRange.IndexOf(c);
            }

            return res;

        }
    }

}

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private static readonly string NRange = new string(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' });

        private void Solve()
        {
            var s = io.NextLine().Split(':');

            s[0] = s[0].TrimStart('0');
            s[1] = s[1].TrimStart('0');

            var min = 0;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    min = Math.Max(min, NRange.IndexOf(s[i][j]));
                }
            }

            if (min > 0)
            {
                List<string> parts = new List<string>();

                var pch = -1;
                var pcm = -1;

                for (int i = min; i < NRange.Length; i++)
                {
                    var ch = Calc10(s[0], i);
                    var cm = Calc10(s[1], i);

                    if (ch < 24 && cm < 60)
                    {
                        if (pch == ch && pcm == cm)
                        {
                            io.Print(-1);
                            return;
                        }

                        parts.Add((i + 1).ToString(CultureInfo.InvariantCulture));
                    }
                    pch = ch;
                    pcm = cm;
                }

                if (parts.Count > 0)
                {
                    io.Print(string.Join(" ", parts.ToArray()));
                    return;
                }
            }

            io.Print(0);
        }

        private int Calc10(string s, int min)
        {
            int res = 0;

            foreach (var c in s)
            {
                res *= (min + 1);
                res += NRange.IndexOf(c);
            }

            return res;

        }
    }

}

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private static readonly string NRange = new string(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' });

        private void Solve()
        {
            var s = io.NextLine().Split(':');

            s[0] = s[0].TrimStart('0');
            s[1] = s[1].TrimStart('0');

            var min = 0;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    min = Math.Max(min, NRange.IndexOf(s[i][j]));
                }
            }

            if (min > 0)
            {
                List<string> parts = new List<string>();

                var pch = -1;
                var pcm = -1;

                for (int i = min; i < NRange.Length; i++)
                {
                    var ch = Calc10(s[0], i);
                    var cm = Calc10(s[1], i);

                    if (ch < 24 && cm < 60)
                    {
                        if (pch == ch && pcm == cm)
                        {
                            io.Print(-1);
                            return;
                        }

                        parts.Add((i + 1).ToString(CultureInfo.InvariantCulture));
                    }
                    pch = ch;
                    pcm = cm;
                }

                if (parts.Count > 0)
                {
                    io.Print(string.Join(" ", parts.ToArray()));
                    return;
                }
                io.Print(0);
                return;
            }

            io.Print(-1);
        }

        private int Calc10(string s, int min)
        {
            int res = 0;

            foreach (var c in s)
            {
                res *= (min + 1);
                res += NRange.IndexOf(c);
            }

            return res;

        }
    }

}

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

namespace ConsoleApplication5
{
    class Program
    {

        static void Main()
        {
            string[] vrem = Console.ReadLine().Split(':');
            char[] a = new char[5];
            char[] b = new char[5];
            int[] a1 = new int[5];
            int[] b1 = new int[5];

            for (int i = vrem[0].Length - 1; i >= 0; i--)
            {
                a[vrem[0].Length - 1 - i] = vrem[0][i];
                if (a[vrem[0].Length - 1 - i] >= 65 && a[vrem[0].Length - 1 - i] <= 90)
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 55);
                else
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 48);
            }
            for (int i = vrem[1].Length - 1; i >= 0; i--)
            {
                b[vrem[1].Length - 1 - i] = vrem[1][i];
                if (b[vrem[1].Length - 1 - i] >= 65 && b[vrem[1].Length - 1 - i] <= 90)
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 55);
                else
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 48);
            }

            int[] otvet = new int[30];

            if (a1[1] >= 2 || a1[0] >= 10)
                Console.WriteLine("0");
            else
            {
                double q = 0;
                double w = 0;
                int k = 3;
                while (k < 30)
                {
                    q = 0;
                    w = 0;
                    for (int i = a1.Length - 1; i >= 0; i--)
                        q = q + a1[i] * Math.Pow(k, i);

                    for (int i = b1.Length - 1; i >= 0; i--)
                        w = w + b1[i] * Math.Pow(k, i);

                    if (q <= 23 && w <= 59)
                        otvet[k] = k;
                    else
                        break;

                    k++;

                }

                if (k == 30)
                    Console.WriteLine("-1");
                else
                {
                    for (int i = 0; i < otvet.Length; i++)
                        if (otvet[i] != 0)
                            Console.Write(otvet[i] + " ");
                }

            }

        }
    }
}

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

namespace ConsoleApplication5
{
    class Program
    {

        static void Main()
        {
            string[] vrem = Console.ReadLine().Split(':');
            char[] a = new char[5];
            char[] b = new char[5];
            int[] a1 = new int[5];
            int[] b1 = new int[5];

            for (int i = vrem[0].Length - 1; i >= 0; i--)
            {
                a[vrem[0].Length - 1 - i] = vrem[0][i];
                if (a[vrem[0].Length - 1 - i] >= 65 && a[vrem[0].Length - 1 - i] <= 90)
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 55);
                else
                    a1[vrem[0].Length - 1 - i] = Convert.ToInt32(a[vrem[0].Length - 1 - i] - 48);
            }
            for (int i = vrem[1].Length - 1; i >= 0; i--)
            {
                b[vrem[1].Length - 1 - i] = vrem[1][i];
                if (b[vrem[1].Length - 1 - i] >= 65 && b[vrem[1].Length - 1 - i] <= 90)
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 55);
                else
                    b1[vrem[1].Length - 1 - i] = Convert.ToInt32(b[vrem[1].Length - 1 - i] - 48);
            }

            int[] otvet = new int[30];

            if (a1[1] >= 2 && a1[0] >= 10)
                Console.WriteLine("0");
            else
            {
                double q = 0;
                double w = 0;
                int k = 3;
                while (k < 30)
                {
                    q = 0;
                    w = 0;
                    for (int i = a1.Length - 1; i >= 0; i--)
                        q = q + a1[i] * Math.Pow(k, i);

                    for (int i = b1.Length - 1; i >= 0; i--)
                        w = w + b1[i] * Math.Pow(k, i);

                    if (q <= 23 && w <= 59)
                        otvet[k] = k;
                    else
                        break;

                    k++;

                }

                if (k == 30)
                    Console.WriteLine("-1");
                else
                {
                    for (int i = 0; i < otvet.Length; i++)
                        if (otvet[i] != 0)
                            Console.Write(otvet[i] + " ");
                }

            }

        }
    }
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFContest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    String[] buf = Console.ReadLine().Split(':');
                    String ret = "";
                    if (can(buf, 1000000))
                    {
                        Console.WriteLine("-1");
                        continue;
                    }
                    for (int i = 2; i <= 1000000; i++)
                    {
                        if (can(buf, i))
                        {
                            ret = ret + i + " ";
                        }
                    }
                    if (ret == "")
                        ret = "0";
                    Console.WriteLine(ret);
                }
            }
            catch (Exception)
            {
            }
        }

        private static bool can(string[] buf, int b)
        {
            int[] d = new int[2];
            for (int i = 0; i < 2; i++)
            {
                d[i] = 0;
                for (int j = 0; j < buf[i].Length; j++)
                {
                    int fd = buf[i][j] >= '0' && buf[i][j] <= '9' ? buf[i][j] - '0' : buf[i][j] - 'A' + 10;
                    if (fd >= b) return false;
                    d[i] = d[i] * b + fd;
                }
            }
            return d[0] >= 0 && d[0] <= 23 && d[1] >= 0 && d[1] <= 59;
        }
    }
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFContest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    String[] buf = Console.ReadLine().Split(':');
                    String ret = "";
                    if (can(buf, 1000000))
                    {
                        Console.WriteLine("-1");
                        continue;
                    }
                    for (int i = 2; i <= 1000000; i++)
                    {
                        if (can(buf, i))
                        {
                            ret = ret + i + " ";
                        }
                    }
                    if (ret == "")
                        ret = "0";
                    Console.WriteLine(ret);
                }
            }
            catch (Exception)
            {
            }
        }

        private static bool can(string[] buf, int b)
        {
            long[] d = new long[2];
            for (int i = 0; i < 2; i++)
            {
                d[i] = 0;
                for (int j = 0; j < buf[i].Length; j++)
                {
                    int fd = buf[i][j] >= '0' && buf[i][j] <= '9' ? buf[i][j] - '0' : buf[i][j] - 'A' + 10;
                    if (fd >= b) return false;
                    d[i] = d[i] * b + fd;
                }
            }
            return d[0] >= 0 && d[0] <= 23 && d[1] >= 0 && d[1] <= 59;
        }
    }
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFContest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    String[] buf = Console.ReadLine().Split(':');
                    String ret = "";
                    if (can(buf, 40))
                    {
                        Console.WriteLine("-1");
                        continue;
                    }
                    for (int i = 2; i <= 36; i++)
                    {
                        if (can(buf, i))
                        {
                            ret = ret + i + " ";
                        }
                    }
                    if (ret == "")
                        ret = "0";
                    Console.WriteLine(ret);
                }
            }
            catch (Exception)
            {
            }
        }

        private static bool can(string[] buf, int b)
        {
            int[] d = new int[2];
            for (int i =0;i<2;i++)
            {
                d[i] = 0;
                for (int j =0;j<buf[i].Length;j++)
                {
                    int fd = buf[i][j] >= '0' && buf[i][j] <= '9' ? buf[i][j] - '0' : buf[i][j] - 'A' + 10;
                    if (fd >= b) return false;
                    d[i] = d[i] * b + fd;
                }
            }
            return d[0] >= 0 && d[0] <= 23 && d[1] >= 0 && d[1] <= 59;
        }
    }
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFContest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    String[] buf = Console.ReadLine().Split(':');
                    String ret = "";
                    if (can(buf, 1024))
                    {
                        Console.WriteLine("-1");
                        continue;
                    }
                    for (int i = 2; i <= 1000000; i++)
                    {
                        if (can(buf, i))
                        {
                            ret = ret + i + " ";
                        }
                    }
                    if (ret == "")
                        ret = "0";
                    Console.WriteLine(ret);
                }
            }
            catch (Exception)
            {
            }
        }

        private static bool can(string[] buf, int b)
        {
            long[] d = new long[2];
            for (int i = 0; i < 2; i++)
            {
                d[i] = 0;
                for (int j = 0; j < buf[i].Length; j++)
                {
                    int fd = buf[i][j] >= '0' && buf[i][j] <= '9' ? buf[i][j] - '0' : buf[i][j] - 'A' + 10;
                    if (fd >= b) return false;
                    d[i] = d[i] * b + fd;
                }
            }
            return d[0] >= 0 && d[0] <= 23 && d[1] >= 0 && d[1] <= 59;
        }
    }
}

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

public class B
{
    public partial class Myon
    {
        static void Main()
        {
            B p = new B();
            p.solve();
        }
    }

    public void solve()
    {
        string[] tmp = stringSplit(':');
        for (int i = 0; i < 2; i++)
        {
            if (tmp[i].Length == 0)
                continue;
            if (tmp[i][0] == '0')
                tmp[i] = tmp[i].Substring(1);
        }//for i
        List<int> res = new List<int>();
        for (int i = 1; i <= 70; i++)
        {
            int mul = 1;
            int h = 0; int m = 0;
            int max = 0;
            for (int j = tmp[0].Length - 1; j >= 0; j--)
            {
                max = Math.Max(max, CharToInt(tmp[0][j]));
                h += CharToInt(tmp[0][j]) * mul;
                mul *= i;
            }//forrev j
            mul = 1;
            for (int j = tmp[1].Length - 1; j >= 0; j--)
            {
                max = Math.Max(max, CharToInt(tmp[1][j]));
                m += CharToInt(tmp[1][j]) * mul;
                mul *= i;
            }//forrev j
            if (max >= i||h>=25||m>=60)
                continue;
            if (h == 24 && m > 0)
                continue;
            res.Add(i);
        }

        foreach (int  t  in res)
        {
            if (t > 60)
            {
                Console.WriteLine(-1);
                return;
            }
        }//foreach t
        if (res.Count == 0)
        {
            Console.WriteLine(0);
            return;
        }
        for (int i = 0; i < res.Count; i++)
        {
            Console.Write(res[i]);
            if(i!=res.Count-1)
                Console.Write(" ");
        }//for i
        Console.WriteLine();
    }

    public static int CharToInt(char c)
    {
        if ('0' <= c && c <= '9')
            return c - '0';
        return c - 'A' + 10;
    }//CharToInt

    public static char IntToChar(int i)
    {
        return (char)(i + 'A');
    }//IntToChar

    string stringRead()
    { return Console.ReadLine(); }

    int intRead()
    { return int.Parse(Console.ReadLine()); }

    long longRead()
    { return long.Parse(Console.ReadLine()); }

    string[] stringSplit(char a)
    { return Console.ReadLine().Split(a); }

    int[] intSplit(char a)
    { return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse); }

    long[] longSplit(char a)
    { return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse); }

    void write(string str)
    {
        Console.WriteLine(str);
    }
}

using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Martian_Clock
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(':');

            int min = Math.Max(2, 1+Math.Max(ss[0].Max(t => Code(t)), ss[1].Max(t => Code(t))));

            int h = Convert(ss[0], min);
            int m = Convert(ss[1], min);

            if (h > 23 || m > 59)
                writer.WriteLine("0");
            else if (h < min && m < min)
                writer.WriteLine("-1");
            else
            {
                for (int i = min;; i++)
                {
                    h = Convert(ss[0], i);
                    m = Convert(ss[1], i);

                    if (h <= 23 && m <= 59)
                    {
                        writer.Write(i);
                        writer.Write(' ');
                    }
                    else break;
                }
            }

            writer.Flush();
        }

        private static int Code(char t)
        {
            return t <= '9' ? t - '0' : t - 'A';
        }

        private static int Convert(string s, int r)
        {
            int ans = 0;

            for (int i = 0; i < s.Length; i++)
            {
                ans = ans*r + Code(s[i]);
            }

            return ans;
        }
    }
}

using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Martian_Clock
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(':');

            int min = Math.Max(2, 1+Math.Max(ss[0].Max(t => Code(t)), ss[1].Max(t => Code(t))));

            int h = Convert(ss[0], min);
            int m = Convert(ss[1], min);

            if (h > 23 || m > 59)
                writer.WriteLine("0");
            else if (h < min && m < min)
                writer.WriteLine("-1");
            else
            {
                for (int i = min;; i++)
                {
                    h = Convert(ss[0], i);
                    m = Convert(ss[1], i);

                    if (h <= 23 && m <= 59)
                    {
                        writer.Write(i);
                        writer.Write(' ');
                    }
                    else break;
                }
            }

            writer.Flush();
        }

        private static int Code(char t)
        {
            return t <= '9' ? t - '0' :11 + (t - 'A');
        }

        private static int Convert(string s, int r)
        {
            int ans = 0;

            for (int i = 0; i < s.Length; i++)
            {
                ans = ans*r + Code(s[i]);
            }

            return ans;
        }
    }
}

using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Martian_Clock
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(':');

            int min = Math.Max(2, Math.Max(ss[0].Max(t => Code(t)), ss[1].Max(t => Code(t))));

            int h = Convert(ss[0], min);
            int m = Convert(ss[1], min);

            if (h > 23 || m > 59)
                writer.WriteLine("0");
            else if (h < min && m < min)
                writer.WriteLine("-1");
            else
            {
                for (int i = min;; i++)
                {
                    h = Convert(ss[0], i);
                    m = Convert(ss[1], i);

                    if (h <= 23 && m <= 59)
                    {
                        writer.Write(i);
                        writer.Write(' ');
                    }
                    else break;
                }
            }

            writer.Flush();
        }

        private static int Code(char t)
        {
            return t <= '9' ? t - '0' : t - 'A';
        }

        private static int Convert(string s, int r)
        {
            int ans = 0;

            for (int i = 0; i < s.Length; i++)
            {
                ans = ans*r + Code(s[i]);
            }

            return ans;
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            //if (GetDigits(initbase, 59) < arr[1].Length && GetDigits(initbase, 23) < arr[0].Length)
            //{
            //    Console.WriteLine(0); return;
            //}
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);
            if (GetDigits(initbase, 59) > arr[1].Length)
            {
                Console.WriteLine(0); return;
            }

            if (hours.Length<=1&& minutes.Length<=1)
            {

                Console.WriteLine(-1); return;
            }

            int basesC = 0;
            List<int> bases = new List<int>();

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            if (GetDigits(initbase, 59) < arr[1].Length && GetDigits(initbase, 23) < arr[0].Length)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            if (GetDecimal(hours, initbase, chars) >= 24 && GetDecimal(minutes, initbase, chars) >= 60)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            if (hours.Length<=1&& minutes.Length<=1)
            {

                Console.WriteLine(-1); return;
            }

            int basesC = 0;
            List<int> bases = new List<int>();

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }
            if (GetDigits(initbase, 59) > arr[1].Length)
            {
                Console.WriteLine(0); return;
            }
            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            if (GetDigits(initbase, 59) < arr[1].Length)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }

        static int GetDigits( int b,int v)
        {
            double res = 0;
            int vv = v;
            while (vv>0)
            {
                vv = vv / b; res += 1;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);

            int basesC = 0;
            List<int> bases = new List<int>();
            if (GetDigits(initbase, 59) > arr[1].Length)
            {
                Console.WriteLine(0); return;
            }
            if (hours.Length <= 1 && minutes.Length <= 1)
            {

                Console.WriteLine(-1); return;
            }

            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {

                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}

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

namespace Martian_Clock
{
    class Program
    {
        static int GetDecimal(string s, int b, Dictionary<char, int> chars)
        {
            double res = 0;
            int cc = s.Length - 1;
            for (int i =0  ; i <s.Length; i++)
            {
                res += chars[s[i]] * Math.Pow((double)b, (double)cc); cc--;
            }

            return (int)res;
        }
        static void Main(string[] args)
        {
            Dictionary<char, int> chars = new Dictionary<char, int>();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int u = 10;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

           s = "0123456789";
             u = 0;
            for (int i = 0; i < s.Length; i++)
            {
                chars.Add(s[i], u); u++;
            }

            //while (true)
            //{
            //    Console.WriteLine(GetDecimal(Console.ReadLine(), 16, chars));
            //}

            s = Console.ReadLine();
            string []arr = s.Split(':');
            string hours = "";
            string minutes = "";
            int hmax = 0;
            int mmax = 0;
            bool x = true;
            for (int i = 0; i < arr[0].Length; i++)
            {
                if (arr[0][i] != '0' || !x)
                {
                    hours += arr[0][i]; x = false;
                    int tem = chars[arr[0][i]];
                    if (tem>hmax)
                    {
                        hmax = tem;
                    }
                }

            }
            x = true;
            for (int i = 0; i < arr[1].Length; i++)
            {
                if (arr[1][i] != '0'||!x)
                {
                    minutes += arr[1][i]; x = false;
                    int tem = chars[arr[1][i]];
                    if (tem > mmax)
                    {
                        mmax = tem;
                    }
                }

            }
            if (hours.Length<=1&& minutes.Length<=1)
            {
                Console.WriteLine(-1); return;
            }

            int basesC = 0;
            List<int> bases = new List<int>();

            hmax++;
            mmax++;
            int initbase = Math.Max(hmax, mmax);
            while (GetDecimal(hours, initbase, chars) < 24 && GetDecimal(minutes, initbase, chars) < 60)
            {
                bases.Add(initbase); initbase++;
                basesC++;
            }

            if (basesC == 0)
            {
                Console.WriteLine(0); return;
            }

            int max = bases.Max();
            foreach (int item in bases)
            {
                if (item !=max)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine(max);
        }
    }
}