#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9, MOD = 1e9 + 7, OO = 2e9, MOD2 = 998244353;
const long long INF = 1e15;
int val(char c) {
  if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
  return c - '0';
}
void runtestcase() {
  string str;
  cin >> str;
  string h, m;
  for (int i = 0; i < str.find(':'); ++i) h.push_back(str[i]);
  for (int i = str.find(':') + 1; i < ((int)str.size()); ++i)
    m.push_back(str[i]);
  vector<int> vec;
  for (int b = 2; b < 100; ++b) {
    long long hh = 00, mm = 0;
    bool valid = 1;
    for (auto it : h) {
      if (val(it) >= b) valid = 0;
      hh = hh * b + val(it);
    }
    for (auto it : m) {
      if (val(it) >= b) valid = 0;
      mm = mm * b + val(it);
    }
    valid &= hh < 24 && mm < 60;
    if (valid) {
      if (b == 99) {
        cout << -1;
        return;
      }
      vec.push_back(b);
    }
  }
  for (auto it : vec) cout << it << ' ';
  if (vec.empty()) cout << 0;
}
int main() {
  cout << fixed << setprecision(9), ios::sync_with_stdio(false),
      cin.tie(nullptr), cout.tie(nullptr);
  int t = 1, tt = 1;
  while (t--) {
    runtestcase();
    ++tt;
  }
}
