#include <bits/stdc++.h>
char s[50], c[10], *pch;
long long a[500], hlen, mlen, h[500], m[500];
int mo, ho;
int ldig(char *x) {
  int i;
  int mx = 0;
  for (i = 0; x[i]; i++) {
    if (isdigit(x[i])) {
      if (x[i] - '0' > mx) mx = x[i] - '0';
    } else if (isalpha(x[i])) {
      if ((x[i] - 'A') + 10 > mx) mx = (x[i] - 'A') + 10;
    }
  }
  return mx;
}
int hour(int n) {
  int i;
  long long tot = 0, po = 1;
  for (i = hlen - 1; i >= 0; i--) {
    if (isdigit(c[i])) {
      tot += (c[i] - '0') * po;
    } else if (isalpha(c[i])) {
      tot += ((c[i] - 'A') + 10) * po;
    }
    po *= n;
  }
  if (tot < 24) {
    h[ho++] = tot;
    return 1;
  } else
    return 0;
}
int minute(int n) {
  int i;
  long long tot = 0, po = 1;
  for (i = mlen - 1; i >= 0; i--) {
    if (isdigit(pch[i])) {
      tot += (pch[i] - '0') * po;
    } else if (isalpha(pch[i])) {
      tot += ((pch[i] - 'A') + 10) * po;
    }
    po *= n;
  }
  if (tot < 60) {
    m[mo++] = tot;
    return 1;
  } else
    return 0;
}
int main() {
  int i, n, fou = 0;
  scanf("%s", &s);
  pch = strtok(s, ":");
  strcpy(c, pch);
  pch = strtok(NULL, ":");
  n = ldig(c);
  fou = ldig(pch);
  hlen = strlen(c);
  mlen = strlen(pch);
  if (fou > n) n = fou;
  n++;
  i = 0;
  mo = 0;
  ho = 0;
  for (; n < 60; n++) {
    if (hour(n) && minute(n))
      a[i++] = n;
    else
      break;
  }
  if (n == 60) {
    n = ho;
    for (i = 0; i < n - 1; i++) {
      if (h[i] != h[i + 1]) break;
      if (m[i] != m[i + 1]) break;
    }
    if (i == n - 1)
      puts("-1");
    else {
      i = 0;
      while (i < n) {
        if (i) printf(" ");
        printf("%d", a[i]);
        i++;
      }
    }
  } else if (i == 0)
    puts("0");
  else {
    n = i;
    for (i = 0; i < n; i++) {
      if (i) printf(" ");
      printf("%d", a[i]);
    }
    puts("");
  }
  return 0;
}
