#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans, sum, tmp;
int MAX, MIN;
char a[20];
int b[20], nb = 0, c[20], nc = 0, d[100], nd = 0;
int main() {
  scanf("%s", a);
  int l = strlen(a), now = 0;
  MAX = 0;
  while (a[now] != ':') {
    if ('0' <= a[now] && a[now] <= '9')
      b[nb++] = a[now] - '0';
    else
      b[nb++] = a[now] - 'A' + 10;
    MAX = max(MAX, b[nb - 1]);
    now++;
  }
  now++;
  while (a[now] != '\0') {
    if ('0' <= a[now] && a[now] <= '9')
      c[nc++] = a[now] - '0';
    else
      c[nc++] = a[now] - 'A' + 10;
    MAX = max(MAX, c[nc - 1]);
    now++;
  }
  MAX++;
  int SUM1, SUM2, chk = 0;
  for (int k = MAX; k <= 60; k++) {
    SUM1 = SUM2 = 0;
    for (int i = nb - 1, j = 1; i >= 0; i--, j *= k) SUM1 += (b[i] * j);
    for (int i = nc - 1, j = 1; i >= 0; i--, j *= k) SUM2 += (c[i] * j);
    if (SUM1 <= 23 && SUM2 <= 59) d[nd++] = k;
  }
  if (nd == 0)
    printf("0");
  else if (d[nd - 1] == 60)
    printf("-1");
  else
    for (int i = 0; i < nd; i++) printf("%d ", d[i]);
}
