#include <bits/stdc++.h>
using namespace std;
int sti(string x, int b) {
  int r = 0;
  int p = 1;
  int d;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] >= 'A' && x[i] <= 'Z')
      d = x[i] - 'A' + 10;
    else
      d = x[i] - '0';
    r += d * p;
    p *= b;
  }
  return r;
}
int main() {
  string s;
  cin >> s;
  int p = s.find(":");
  string h = s.substr(0, p);
  string m = s.substr(p + 1);
  reverse(h.begin(), h.end());
  reverse(m.begin(), m.end());
  int bg = 1;
  int d;
  for (int i = 0; i < h.size(); i++) {
    if (h[i] >= 'A' && h[i] <= 'Z')
      d = h[i] - 'A' + 10;
    else
      d = h[i] - '0';
    bg = max(d + 1, bg);
  }
  for (int i = 0; i < m.size(); i++) {
    if (m[i] >= 'A' && m[i] <= 'Z')
      d = m[i] - 'A' + 10;
    else
      d = m[i] - '0';
    bg = max(d + 1, bg);
  }
  vector<int> anw;
  for (int i = bg; i < 70; i++) {
    int hh = sti(h, i);
    int mm = sti(m, i);
    if (hh <= 23 && mm <= 59) {
      anw.push_back(i);
      if (i > 60) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (anw.size() == 0)
    cout << 0 << endl;
  else {
    for (int i = 0; i < anw.size(); i++) {
      if (i != 0) cout << ' ';
      cout << anw[i];
    }
    cout << endl;
  }
}
