#include <bits/stdc++.h>
using namespace std;
int value(char x) {
  if (isdigit(x)) return x - '0';
  return (x - 'A') + 10;
}
long long shifting(string x, int b) {
  long long sum = 0, temp = 1;
  for (int i = x.size() - 1; i >= 0; i--) {
    sum += temp * value(x[i]);
    temp *= b;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  ;
  string h, m;
  cin >> h;
  m = h.substr(h.find(":") + 1);
  h = h.substr(0, h.find(":"));
  while (h.size() > 1 and h[0] == '0') h.erase(0, 1);
  while (m.size() > 1 and m[0] == '0') m.erase(0, 1);
  if (h.size() == 1 and m.size() == 1 and value(h[0]) < 24 and value(m[0]) < 60)
    return cout << -1, 0;
  int maxb = 0;
  for (int i = h.size() - 1; i >= 0; i--) maxb = max(maxb, value(h[i]));
  for (int i = m.size() - 1; i >= 0; i--) maxb = max(maxb, value(m[i]));
  bool is = 0;
  for (int i = maxb + 1; i < 61; i++) {
    long long hh, mm;
    hh = shifting(h, i);
    mm = shifting(m, i);
    if (hh < 24 and mm < 60) is = 1, cout << i << " ";
  }
  if (!is) cout << 0;
  return 0;
}
