#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p) {
  return os << p.first << ',' << p.second;
}
template <typename T>
struct point {
  T x, y;
  point(T xx = 0, T yy = 0) : x(xx), y(yy) {}
  T len2() const { return x * x + y * y; }
  double len() const { return sqrt(double(len2())); }
  bool operator==(const point<T>& p) const { return x == p.x && y == p.y; }
};
template <typename T>
point<T> operator+(const point<T>& a, const point<T>& b) {
  return point<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
point<T> operator-(const point<T>& a, const point<T>& b) {
  return point<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
T scal(const point<T>& a, const point<T>& b) {
  return a.x * b.x + a.y * b.y;
}
template <typename T>
T vect(const point<T>& a, const point<T>& b) {
  return a.x * b.y - a.y * b.x;
}
template <typename T>
ostream& operator<<(ostream& os, const point<T>& p) {
  return os << '(' << p.x << ',' << p.y << ')';
}
int todigit(char x) {
  if (isdigit(x)) return x - '0';
  return x - 'A' + 10;
}
int toint(const string& s, int k) {
  int q = 0;
  for (int i = 0; i < s.size(); i++) {
    if (todigit(s[i]) >= k) {
      return -1;
    }
    q = q * k + todigit(s[i]);
    if (q > 60) return q;
  }
  return q;
}
int main() {
  string s;
  cin >> s;
  int p = s.find(':');
  string a(s.substr(0, p));
  string b(s.substr(p + 1));
  int res = 0;
  for (int i = 2; i < 1000; i++) {
    int h = toint(a, i);
    int m = toint(b, i);
    if (h < 0 || m < 0) continue;
    if (h >= 24 || m >= 60) continue;
    res++;
  }
  if (res > 900) {
    puts("-1");
  } else if (!res) {
    puts("0");
  } else {
    for (int i = 2; i < 1000; i++) {
      int h = toint(a, i);
      int m = toint(b, i);
      if (h < 0 || m < 0) continue;
      if (h >= 24 || m >= 60) continue;
      printf("%d ", i);
    }
  }
  return 0;
}
