#include <bits/stdc++.h>
using namespace std;
vector<int> resp;
string h, m;
bool sirve(int a) {
  int hh = 0, mm = 0;
  int n = 0;
  int pot = 1;
  for (int i = h.size() - 1; i >= 0; i--) {
    if (h[i] <= '9')
      n = h[i] - '0';
    else
      n = h[i] - 'A' + 10;
    if (n >= a) return false;
    hh += n * pot;
    pot *= a;
  }
  pot = 1;
  for (int i = m.size() - 1; i >= 0; i--) {
    if (m[i] <= '9')
      n = m[i] - '0';
    else
      n = m[i] - 'A' + 10;
    if (n >= a) return false;
    mm += n * pot;
    pot *= a;
  }
  if (hh > 23 || mm > 59) return false;
  return true;
}
int main() {
  string cad;
  cin >> cad;
  int i = 0;
  while (cad[i] != ':') {
    h += cad[i];
    i++;
  }
  i++;
  while (i < cad.size()) {
    m += cad[i];
    i++;
  }
  int base = 2;
  bool flag = false;
  while (1) {
    if (sirve(base)) {
      resp.push_back(base);
      flag = true;
    } else {
      if (flag) break;
    }
    base++;
    if (base > 60) break;
  }
  if (!flag) {
    cout << "0" << endl;
    return 0;
  }
  if (base > 60) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < resp.size(); i++) {
    cout << resp[i] << " ";
  }
  cout << endl;
}
