#include <bits/stdc++.h>
using namespace std;
int toDigit(char c) {
  if ('0' <= c && c <= '9') return c - '0';
  return c - 'A' + 10;
}
int toInteger(string a, int k) {
  int ret = 0;
  for (int i = 0; i < (int)(a.length()); i++) {
    int x = toDigit(a[i]);
    if (x >= k) return -1;
    ret = k * ret + x;
    if (ret >= 60) return -1;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  size_t pos = str.find(':');
  string a = str.substr(0, pos);
  string b = str.substr(pos + 1);
  vector<int> ret;
  bool inf = false;
  for (int k = 2; k < 60; k++) {
    int x = toInteger(a, k);
    int y = toInteger(b, k);
    if (x < 0 || x > 23) continue;
    if (y < 0 || y > 59) continue;
    ret.push_back(k);
    if (x < k && y < k) inf = true;
  }
  if (inf)
    cout << -1 << endl;
  else if (!ret.size())
    cout << 0 << endl;
  else {
    for (int i = 0; i < (int)(ret.size()); i++) cout << ret[i] << " ";
    cout << endl;
  }
  return 0;
}
