#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, a, b, c;
  cin >> s;
  map<char, int> A;
  int p = 0;
  for (char i = '0'; i <= '9'; i++) {
    A[i] = p;
    p++;
  }
  for (char i = 'A'; i <= 'Z'; i++) {
    A[i] = p;
    p++;
  }
  a = s.substr(0, s.find(':'));
  b = s.substr(s.find(':') + 1, s.length() - s.find(':'));
  while (a.length() > 1 && a[0] == '0') a.erase(0, 1);
  while (b.length() > 1 && b[0] == '0') b.erase(0, 1);
  c = a + b;
  char w = c[0];
  for (int i = 1; i < c.length(); i++)
    if (c[i] > w) w = c[i];
  int pos = A[w] + 1;
  int size = 0;
  if (a.length() == 1 && b.length() == 1 && A[a[0]] < 24 && A[b[0]] < 60)
    cout << -1;
  else {
    for (int i = pos; i <= 60; i++) {
      int h = 0, m = 0;
      for (int j = 0; j < a.length(); j++) {
        h = h * i + A[a[j]];
      }
      for (int j = 0; j < b.length(); j++) {
        m = m * i + A[b[j]];
      }
      if (h < 24 && m < 60) size++, cout << i << ' ';
    }
    if (!size) cout << 0;
  }
}
