#include <bits/stdc++.h>
using namespace std;
int deg[160];
vector<int> vec;
string s1, s2;
int mn = 0;
bool isNum(char t) { return (t - '0' >= 0 && t - '0' <= 9); }
bool isAlpha(char t) { return (t >= 'A' && t <= 'Z'); }
int cevir(int a) {
  int k = 0;
  while (a) {
    k = (10 * k) + a % 10;
    a /= 10;
  }
  return k;
}
void read() {
  for (int i = '0'; i <= '9'; i++) deg[i] = i - '0';
  for (int i = 'A'; i <= 'Z'; i++) deg[i] = i - 55;
  string s3;
  cin >> s3;
  bool k = 0;
  for (int i = 0; i < s3.size(); i++) {
    mn = max(mn, deg[s3[i]]);
    if (!k) {
      if (s3[i] == ':')
        k = 1;
      else
        s1 += s3[i];
    } else if (k) {
      s2 += s3[i];
    }
  }
  mn++;
}
bool knt() {
  int k = 1;
  int tp1 = 0, tp2 = 0;
  for (int i = s1.size() - 1; i >= 0; i--) {
    tp1 += k * deg[s1[i]];
    k *= mn;
  }
  k = 1;
  for (int i = s2.size() - 1; i >= 0; i--) {
    tp2 += k * deg[s2[i]];
    k *= mn;
  }
  if (tp1 >= 24 || tp2 >= 60) return 0;
  return 1;
}
int main() {
  read();
  while (knt()) {
    vec.push_back(mn);
    mn++;
    if (mn > 100) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (vec.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < vec.size(); i++) cout << vec[i] << " ";
  return 0;
}
