#include <bits/stdc++.h>
using namespace std;
int calc(string t, int n) {
  int ans;
  if (t[t.length() - 1] >= 'A' && t[t.length() - 1] <= 'Z')
    ans = t[t.length() - 1] - 'A' + 10;
  else
    ans = t[t.length() - 1] - '0';
  int mul = n;
  for (int i = t.length() - 2; i >= 0; i--) {
    if (t[i] >= 'A' && t[i] <= 'Z')
      ans += (t[i] - 'A' + 10) * mul;
    else
      ans += (t[i] - '0') * mul;
    mul *= n;
  }
  return ans;
}
int main() {
  string h, m, s;
  cin >> s;
  h = s.substr(0, s.find(":"));
  m = s.substr(s.find(":") + 1, s.length() - s.find(":") - 1);
  for (int i = 0; i < h.length() - 1; i++) {
    if (h[i] == '0') {
      h = h.substr(1, h.length() - 1);
      i--;
    } else
      break;
  }
  for (int i = 0; i < m.length() - 1; i++) {
    if (m[i] == '0') {
      m = m.substr(1, m.length() - 1);
      i--;
    } else
      break;
  }
  bool flag = true;
  vector<int> v;
  if (h.length() <= 1 && m.length() <= 1) {
    if ((h.length() == 1 &&
         ((h[0] >= '0' && h[0] <= '9') || (h[0] - 'A' + 10) < 24)) &&
        (m.length() == 1 &&
         ((m[0] >= '0' && m[0] <= '9') || (m[0] - 'A' + 10) < 60)))
      flag = false;
  } else {
    int st = 0;
    for (int i = 0; i < h.length(); i++)
      if (h[i] >= 'A' && h[i] <= 'Z')
        st = st > (h[i] - 'A' + 10) ? st : (h[i] - 'A' + 10);
      else
        st = st > (h[i] - '0') ? st : (h[i] - '0');
    for (int i = 0; i < m.length(); i++)
      if (m[i] >= 'A' && m[i] <= 'Z')
        st = st > (m[i] - 'A' + 10) ? st : (m[i] - 'A' + 10);
      else
        st = st > (m[i] - '0') ? st : (m[i] - '0');
    st += 1;
    for (int i = st;; i++) {
      if (calc(h, i) < 24 && calc(m, i) < 60)
        v.push_back(i);
      else
        break;
    }
  }
  if (!flag)
    cout << "-1" << endl;
  else {
    if (v.size() == 0)
      cout << "0" << endl;
    else
      for (int i = 0; i < v.size(); i++) printf("%d ", v[i]);
  }
  return 0;
}
