#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  string s;
  string st1 = "", st2 = "";
  cin >> s;
  vector<int> ans;
  int n = s.size();
  int cnt1 = 0, nz1 = 0, cnt2 = 0, nz2 = 0;
  int i = 0;
  while (s[i] != ':') {
    cnt1++;
    if (s[i] == '0') nz1++;
    st1 += s[i];
    i++;
  }
  i++;
  while (i < n) {
    cnt2++;
    st2 += s[i];
    if (s[i] == '0') nz2++;
    i++;
  }
  if (nz1 == cnt1 && nz2 == cnt2)
    cout << -1 << "\n";
  else if ((nz1 == (cnt1 - 1) && nz2 == cnt2) &&
           ((st1[st1.size() - 1] <= 'N' && st1[st1.size() - 1] != '0'))) {
    cout << -1 << "\n";
  } else if ((nz1 == (cnt1) && nz2 == (cnt2 - 1)) &&
             ((st2[st2.size() - 1] != '0'))) {
    cout << -1 << "\n";
  } else if ((nz1 == (cnt1 - 1) && nz2 == (cnt2 - 1)) &&
             ((st1[st1.size() - 1] != '0' && st2[st2.size() - 1] != '0' &&
               st1[st1.size() - 1] <= 'N'))) {
    cout << -1 << "\n";
  } else {
    int str = 3;
    int cmp = -1;
    for (int i = 0; i < s.size(); i++)
      if (s[i] > cmp && s[i] != ':') cmp = s[i];
    cmp -= 48;
    if (cmp <= 9)
      str = cmp + 1;
    else
      str = cmp + 48 - 65 + 10 + 1;
    while (true) {
      int calc1 = 0, calc2 = 0;
      int nm = 1;
      for (int j = st1.size() - 1; j >= 0; j--) {
        if (st1[j] <= '9') {
          int md = st1[j] - 48;
          calc1 += md * nm;
        } else {
          int md = st1[j] - 65 + 10;
          calc1 += md * nm;
        }
        nm = nm * str;
      }
      nm = 1;
      for (int j = st2.size() - 1; j >= 0; j--) {
        if (st2[j] <= '9') {
          int md = st2[j] - 48;
          calc2 += md * nm;
        } else {
          int md = st2[j] - 65 + 10;
          calc2 += md * nm;
        }
        nm = nm * str;
      }
      if (calc1 < 24 && calc2 < 60)
        ans.push_back(str);
      else
        break;
      str++;
    }
    if (ans.size() == 0)
      cout << 0 << "\n";
    else {
      for (int j = 0; j < ans.size(); j++) cout << ans[j] << " ";
      cout << "\n";
    }
  }
}
