#include <bits/stdc++.h>
using namespace std;
int xx[] = {1, 1, 1, 0, -1, -1, -1, 0};
int yy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
long long int gcd(long long int a, long long int b) {
  return ((a % b == 0) ? b : gcd(b, a % b));
}
int cal(int mal, int times) {
  int h = 1, i;
  for (i = 0; i < times; i++) h = h * mal;
  return h;
}
int main() {
  int i, j, len, tmp;
  map<char, int> my;
  vector<int> res;
  for (i = 0; i < 10; i++) {
    my[(char)(i + 48)] = i;
  }
  for (i = 0; i < 26; i++) {
    my[(char)(i + 65)] = i + 10;
  }
  bool f = true;
  string str, s1, s2;
  cin >> str;
  len = str.size();
  for (i = 0; i < len; i++) {
    if (str[i] == ':') {
      f = false;
      continue;
    }
    if (f)
      s1 += str[i];
    else
      s2 += str[i];
  }
  len = s1.size();
  for (i = 0; i < len; i++) {
    if (s1[i] == '0') {
      s1.erase(s1.begin());
      i--;
    } else
      break;
  }
  len = s2.size();
  for (i = 0; i < len; i++) {
    if (s2[i] == '0') {
      s2.erase(s2.begin());
      i--;
    } else
      break;
  }
  tmp = 0;
  reverse(s1.begin(), s1.end());
  reverse(s2.begin(), s2.end());
  for (i = 0; i < s1.size(); i++) {
    tmp = max(my[s1[i]], tmp);
  }
  for (i = 0; i < s2.size(); i++) {
    tmp = max(my[s2[i]], tmp);
  }
  int m, n, l1, l2;
  l1 = s1.size();
  l2 = s2.size();
  for (i = tmp + 1; i <= 60; i++) {
    m = n = 0;
    for (j = 0; j < l1; j++) {
      m += (cal(i, j) * my[s1[j]]);
    }
    for (j = 0; j < l2; j++) {
      n += (cal(i, j) * my[s2[j]]);
    }
    if (m < 24 && n < 60) {
      res.push_back(i);
    }
  }
  if (res.size() == 0) {
    printf("0\n");
    return 0;
  }
  if (res[res.size() - 1] == 60) {
    printf("-1\n");
    return 0;
  }
  l1 = res.size();
  for (i = 0; i < l1; i++) {
    cout << res[i] << " ";
  }
  cout << endl;
  return 0;
}
