#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 8;
const int MAX_H = 24;
const int MAX_M = 60;
char s[16];
int hds[MAX_N], mds[MAX_N], bs[MAX_M];
int parse(char *(&cpt), int ds[]) {
  int n = 0;
  while (*cpt == ':') cpt++;
  while (*cpt == '0') cpt++;
  for (; *cpt && *cpt != ':'; cpt++)
    ds[n++] = (*cpt >= '0' && *cpt <= '9') ? *cpt - '0' : *cpt - 'A' + 10;
  return n;
}
int calc(int ds[], int n, int b) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (ds[i] >= b) return -1;
    sum = sum * b + ds[i];
  }
  return sum;
}
void printds(int ds[], int n) {
  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", ds[i]);
  }
  putchar('\n');
}
int main() {
  scanf("%s", s);
  char *cpt = s;
  int hn = parse(cpt, hds);
  int mn = parse(cpt, mds);
  if (hn <= 1 && mn <= 1 && calc(hds, hn, MAX_M) < MAX_H &&
      calc(mds, mn, MAX_M) < MAX_M) {
    puts("-1");
    return 0;
  }
  int bn = 0;
  for (int b = 2; b <= MAX_M; b++) {
    int h = calc(hds, hn, b);
    int m = calc(mds, mn, b);
    if (h < 0 || m < 0) continue;
    if (h >= MAX_H || m >= MAX_M) break;
    bs[bn++] = b;
  }
  if (bn > 0)
    printds(bs, bn);
  else
    puts("0");
  return 0;
}
