#include <bits/stdc++.h>
char t[10000];
int l;
bool isOk(int n) {
  int s = 0, m = 0, q = 0;
  for (int i = 0; i < l; i++) {
    if (t[i] == 50) {
      q = 1;
      continue;
    }
    if (t[i] >= n) return false;
    if (q)
      m = m * n + t[i];
    else
      s = s * n + t[i];
    if (s > 23 || m > 59) return false;
  }
  return true;
}
int main() {
  gets(t);
  l = strlen(t);
  for (int i = 0; i < l; i++)
    t[i] = '0' <= t[i] && t[i] <= '9'     ? (t[i] - '0')
           : ('A' <= t[i] && t[i] <= 'Z') ? (t[i] - 'A' + 10)
                                          : 50;
  if (isOk(100)) {
    printf("%d\n", -1);
    return 0;
  }
  int c = 0;
  for (int i = 1; i <= 61; i++)
    if (isOk(i)) printf("%d ", i), c++;
  if (!c) puts("0");
  return 0;
}
