#include <bits/stdc++.h>
using namespace std;
char s[15];
int p(char ch) {
  if ('0' <= ch && ch <= '9') return ch - '0';
  return ch - 'A' + 10;
}
int work(char s[], int base) {
  int ans = 0, t;
  for (int i = 0; s[i]; i++) {
    t = p(s[i]);
    if (t >= base) return 100;
    ans = ans * base + t;
  }
  return ans;
}
int main() {
  int i, j;
  int m, n, k;
  int a[61];
  while (scanf("%s", s) != EOF) {
    m = strlen(s);
    for (i = 0; i < m; i++)
      if (s[i] == ':') {
        s[i] = '\0';
        k = i;
      }
    for (i = 2, j = 0; i <= 60; i++)
      if (work(s, i) < 24 && work(&s[k + 1], i) < 60) a[j++] = i;
    if (j == 0)
      printf("0\n");
    else if (a[j - 1] == 60)
      printf("-1\n");
    else {
      for (i = 0; i < j; i++)
        if (i)
          printf(" %d", a[i]);
        else
          printf("%d", a[i]);
      printf("\n");
    }
  }
  return 0;
}
