#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkmin(T &a, T b) {
  if (a > b) a = b;
}
int to(char c) {
  int res = 0;
  if (c >= '0' && c <= '9')
    res = c - '0';
  else
    res = c - 'A' + 10;
  return res;
}
int convert(string s, int base) {
  int res = 0;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    if (to(s[i]) >= base) return -1;
    res = res * base + to(s[i]);
  }
  return res;
}
void solve() {
  string s, a, b;
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    if (s[i] == ':') {
      a = s.substr(0, i);
      b = s.substr(i + 1);
    }
  }
  vector<int> vb;
  for (int i = 2; i <= 60; i++) {
    int x = convert(a, i);
    int y = convert(b, i);
    if (x != -1 && y != -1) {
      if (x >= 0 && x <= 23 && y >= 0 && y <= 59) vb.push_back(i);
    }
  }
  int sz = vb.size();
  if (sz == 0)
    cout << sz << endl;
  else if (vb[sz - 1] == 60)
    cout << -1 << endl;
  else {
    for (int i = 0; i < sz; i++) {
      cout << vb[i];
      if (i < sz - 1) cout << " ";
    }
    cout << endl;
  }
}
int main() {
  solve();
  return 0;
}
