#include <bits/stdc++.h>
using namespace std;
char str[20];
int la, lb, a[8], b[8], v[100], c[200], z;
int minr = 1;
int main() {
  for (int i = '0'; i <= '9'; i++) c[i] = i - '0';
  for (int i = 'A'; i <= 'Z'; i++) c[i] = i - 'A' + 10;
  scanf("%s", str + 1);
  for (int i = 1; str[i]; i++) {
    if (str[i] != ':') {
      a[++la] = c[str[i]];
      minr = max(a[la], minr);
    } else if (str[i] == ':') {
      int j = 0;
      for (int j = i + 1; str[j]; j++)
        b[++lb] = c[str[j]], minr = max(minr, b[lb]);
      break;
    }
  }
  for (int i = minr + 1; i <= 70; i++) {
    int t1 = 0, t2 = 0;
    for (int j = la, k = 1; j; j--, k *= i) t1 += a[j] * k;
    for (int j = lb, k = 1; j; j--, k *= i) t2 += b[j] * k;
    if (0 <= t1 && t1 <= 23 && 0 <= t2 && t2 <= 59) v[i] = 1;
  }
  for (int i = 1; i <= 70; i++)
    if (v[i]) z++;
  if (z == 70 - minr)
    cout << -1;
  else if (!z)
    cout << 0;
  else
    for (int i = 1; i <= 59; i++)
      if (v[i]) cout << i << ' ';
  return 0;
}
