#include <bits/stdc++.h>
using namespace std;
char str[30];
char a[10], b[10];
bool chk(int r) {
  int rr = 1;
  int i = strlen(a);
  int j = strlen(b);
  i--;
  j--;
  int s = 0, t = 0;
  while (i >= 0) {
    int tmp;
    if (isdigit(a[i]))
      tmp = a[i] - '0';
    else
      tmp = a[i] - 'A' + 10;
    s += rr * tmp;
    rr *= r;
    if (s > 23) return false;
    i--;
  }
  rr = 1;
  while (j >= 0) {
    int tmp;
    if (isdigit(b[j]))
      tmp = b[j] - '0';
    else
      tmp = b[j] - 'A' + 10;
    t += rr * tmp;
    rr *= r;
    if (t > 59) return false;
    j--;
  }
  return true;
}
int main() {
  while (scanf("%s", str) != -1) {
    int i, j;
    int len = strlen(str);
    j = 0;
    int ma = 0, mb = 0;
    int maxm = 0;
    for (i = 0; i < len; i++) {
      if (isdigit(str[i])) ma = max(ma, str[i] - '0');
      if (isalpha(str[i])) ma = max(ma, str[i] - 'A' + 10);
      if (str[i] == ':') break;
      a[j++] = str[i];
    }
    a[j] = '\0';
    for (i += 1, j = 0; i < len; i++) {
      if (isdigit(str[i])) mb = max(mb, str[i] - '0');
      if (isalpha(str[i])) mb = max(mb, str[i] - 'A' + 10);
      b[j++] = str[i];
    }
    b[j] = '\0';
    bool ok = 0;
    int cnt = 0;
    int ll = strlen(a);
    bool g1 = 0, g2 = 0;
    for (i = 0; i < ll; i++) {
      if (a[i] != '0' && cnt == ll - 1 && i == ll - 1) {
        g1 = 1;
        break;
      } else if (a[i] == '0')
        cnt++;
    }
    if (cnt == ll) g1 = 1;
    ll = strlen(b);
    cnt = 0;
    for (i = 0; i < ll; i++) {
      if (b[i] != '0' && cnt == ll - 1 && i == ll - 1) {
        g2 = 1;
        break;
      } else if (b[i] == '0')
        cnt++;
    }
    if (cnt == ll) g2 = 1;
    if (g1 && g2 && ma <= 23 && mb <= 59) {
      cout << -1 << endl;
      continue;
    } else if (g1 && g2 && (ma > 23 || mb > 59)) {
      cout << 0 << endl;
      continue;
    }
    maxm = max(ma, mb);
    for (i = maxm + 1;; i++) {
      if (chk(i)) {
        cout << i << " ";
        ok = 1;
      } else
        break;
    }
    if (!ok) cout << 0;
    cout << endl;
  }
  return 0;
}
