#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
int c2i(char c) {
  if (c <= '9') return c - '0';
  return c - 'A' + 10;
}
long long conv(string num, int base) {
  long long res = 0;
  for (int i = 0; i < (int)num.length(); i++) {
    if (c2i(num[i]) >= base) return INF;
    res = res * base + c2i(num[i]);
  }
  return res;
}
int main() {
  string inp, h, m;
  cin >> inp;
  for (int i = 0; i < (int)inp.length(); i++)
    if (inp[i] == ':') inp[i] = ' ';
  istringstream sin(inp);
  sin >> h >> m;
  vector<int> res;
  for (int base = 2; base <= 100; base++)
    if (conv(h, base) < 24 && conv(m, base) < 60) res.push_back(base);
  if (res.empty())
    cout << 0 << endl;
  else if (res.back() == 100)
    cout << -1 << endl;
  else {
    for (int i = 0; i < (int)res.size(); i++) cout << res[i] << " ";
    cout << endl;
  }
  return 0;
}
