#include <bits/stdc++.h>
using namespace std;
int convertStringToNumberBase(string number, int base) {
  int r = 1;
  int val = 0;
  for (int i = number.size() - 1; i >= 0; i--) {
    int charVal = number[i] - '0';
    if (number[i] >= 'A') {
      charVal = number[i] - 'A' + 10;
    }
    if (charVal >= base) return 61;
    val += r * (charVal);
    r *= base;
  }
  return val;
}
int main() {
  string time;
  string a, b;
  cin >> time;
  int delimiterPos = time.find(':');
  a = time.substr(0, delimiterPos);
  b = time.substr(delimiterPos + 1);
  cerr << a << " " << b << endl;
  bool checked = false;
  vector<int> validBases;
  for (int i = 2; i < 61; i++) {
    int ab10 = convertStringToNumberBase(a, i);
    int bB10 = convertStringToNumberBase(b, i);
    if (ab10 < 24 && bB10 < 60) {
      validBases.push_back(i);
    }
  }
  int ab10 = convertStringToNumberBase(a, 61);
  int bB10 = convertStringToNumberBase(b, 61);
  if (ab10 < 24 && bB10 < 60) {
    cout << -1 << endl;
    return 0;
  }
  if (validBases.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int j = 0; j < validBases.size(); ++j) {
    cout << validBases[j] << " ";
  }
  return 0;
}
