#include <bits/stdc++.h>
using namespace std;
int char2int(char ch) {
  if (ch >= '0' && ch <= '9') return ch - '0';
  return ch - 'A' + 10;
}
char buf[20], *a = NULL, *b = NULL, *ptr = NULL;
int hour, minute;
void GetHM(int radix) {
  hour = minute = 0;
  ptr = a;
  while ((*ptr) != 0) {
    hour = hour * radix + char2int(*ptr);
    ++ptr;
  }
  ptr = b;
  while ((*ptr) != 0) {
    minute = minute * radix + char2int(*ptr);
    ++ptr;
  }
}
int main() {
  scanf("%s", buf);
  a = strtok(buf, ":");
  b = strtok(NULL, ":");
  int min_r = 2;
  ptr = a;
  while ((*ptr) != 0) {
    min_r = max(min_r, char2int(*ptr) + 1);
    ++ptr;
  }
  ptr = b;
  while ((*ptr) != 0) {
    min_r = max(min_r, char2int(*ptr) + 1);
    ++ptr;
  }
  GetHM(min_r);
  if (hour >= 24 || minute >= 60) {
    printf("0\n");
    return 0;
  }
  GetHM(60);
  if (hour < 24 && minute < 60) {
    printf("-1\n");
    return 0;
  }
  bool first = true;
  for (int i = min_r; i < 60; ++i) {
    GetHM(i);
    if (hour >= 24 || minute >= 60) continue;
    if (!first)
      printf(" ");
    else
      first = false;
    printf("%d", i);
  }
  printf("\n");
  return 0;
}
