#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
int toint(char c) {
  if (c <= '9') return c - '0';
  return c - 'A' + 10;
}
long long conv(string s, int b) {
  long long ret = 0;
  for (int i = 0; i < (int)s.length(); ++i) {
    if (toint(s[i]) >= b) return INF;
    ret = ret * b + toint(s[i]);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, m = "", h = "";
  cin >> s;
  for (int i = 0; i < (int)s.length(); ++i) {
    if (s[i] == ':') {
      for (int j = 0; j < i; ++j) h += s[j];
      for (int k = i + 1; k < (int)s.length(); ++k) m += s[k];
    }
  }
  vector<int> v;
  for (int i = 2; i <= 100; ++i) {
    if (conv(h, i) < 24 and conv(m, i) < 60) v.push_back(i);
  }
  if (!v.size())
    cout << "0";
  else if (v.back() == 100)
    cout << "-1";
  else
    for (auto it : v) cout << it << " ";
  return 0;
}
