#include <bits/stdc++.h>
using namespace std;
const int modN = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841;
int base[100];
void init() {
  memset(base, -1, sizeof(base));
  int i;
  for (i = 48; i < 58; i++) base[i] = i - 47;
  for (i = 65; i < 100; i++) base[i] = i - 54;
}
bool verifica(int bas, string nro) {
  int i, j, hora, minu, x, pos;
  string a, b;
  for (i = 0; i < nro.size(); i++) {
    if (nro[i] == ':') break;
  }
  a = nro.substr(0, i);
  b = nro.substr(i + 1, nro.size() - i - 1);
  pos = 0, j = 0;
  for (i = a.size() - 1; i >= 0; i--) {
    pos += (pow(bas, j) * (base[a[i]] - 1));
    j++;
  }
  hora = pos;
  pos = 0, j = 0;
  for (i = b.size() - 1; i >= 0; i--) {
    pos += (pow(bas, j) * (base[b[i]] - 1));
    j++;
  }
  minu = pos;
  return ((0 <= hora && hora <= 23) && (0 <= minu && minu <= 59));
}
int main() {
  string x;
  init();
  while (cin >> x) {
    int i;
    char may = '0';
    for (i = 0; i < x.size(); i++) {
      if (x[i] == ':') continue;
      may = max(may, x[i]);
    }
    vector<int> vec;
    vec.clear();
    bool sw = 1;
    for (i = base[may]; i < 100; i++) {
      if (verifica(i, x))
        vec.push_back(i);
      else
        break;
    }
    if (vec.size() == 0) {
      printf("0\n");
      continue;
    } else if (vec.back() == 99) {
      printf("-1\n");
      continue;
    } else
      for (i = 0; i < vec.size() - 1; i++) printf("%d ", vec[i]);
    printf("%d\n", vec[i]);
  }
  return 0;
}
