#include <bits/stdc++.h>
using namespace std;
bool ckeck(int s, string h, string m) {
  int hn = 0, mn = 0;
  int step = 1;
  for (int i = h.length() - 1; i >= 0; i--) {
    if (isalpha(h[i]))
      hn += (h[i] - 'A' + 10) * step;
    else
      hn += (h[i] - '0') * step;
    step *= s;
  }
  step = 1;
  for (int i = m.length() - 1; i >= 0; i--) {
    if (isalpha(m[i]))
      mn += (m[i] - 'A' + 10) * step;
    else
      mn += (m[i] - '0') * step;
    step *= s;
  }
  if (hn <= 23 && mn <= 59) return true;
  return false;
}
int main() {
  string s, s1, s2;
  string h, m;
  cin >> s;
  int p = s.find(':');
  s1 = s.substr(0, p);
  s2 = s.substr(p + 1);
  int i = 0;
  while (s1[i] == '0') i++;
  h = s1.substr(i);
  i = 0;
  while (s2[i] == '0') i++;
  m = s2.substr(i);
  if (h.length() == 0) h.push_back(0);
  if (m.length() == 0) m.push_back(0);
  if (h.length() == 1 && m.length() == 1) {
    if ((isalpha(h[0]) && h[0] > 'N')) {
      cout << 0;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  }
  int minsystem = 2;
  for (int i = 0; i < h.length(); i++)
    if (isalpha(h[i]))
      minsystem = max(minsystem, h[i] - 'A' + 11);
    else
      minsystem = max(minsystem, h[i] - '0' + 1);
  for (int i = 0; i < m.length(); i++)
    if (isalpha(m[i]))
      minsystem = max(minsystem, m[i] - 'A' + 11);
    else
      minsystem = max(minsystem, m[i] - '0' + 1);
  vector<int> answ;
  int k = minsystem;
  while (ckeck(k, h, m)) {
    answ.push_back(k);
    k++;
  }
  if (answ.size() == 0)
    cout << 0;
  else
    for (int i = 0; i < answ.size(); i++) cout << answ[i] << " ";
  return 0;
}
