#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int main() {
  long l1, l2, p, i, j, k, sum, l, flag, max;
  char s[100];
  while (cin >> s) {
    l1 = 0;
    l2 = 0;
    flag = 1;
    max = 0;
    while (s[l1] != ':') {
      if (s[l1] >= '0' && s[l1] <= '9')
        a[l1] = s[l1] - '0';
      else
        a[l1] = s[l1] - 'A' + 10;
      if (max < a[l1]) max = a[l1];
      l1++;
    }
    while (s[l1 + l2 + 1] != '\0') {
      if (s[l1 + l2 + 1] >= '0' && s[l1 + l2 + 1] <= '9')
        b[l2] = s[l1 + l2 + 1] - '0';
      else
        b[l2] = s[l1 + l2 + 1] - 'A' + 10;
      if (max < b[l2]) max = b[l2];
      l2++;
    }
    for (p = max + 1; p < 70; p++) {
      sum = 0;
      k = 1;
      for (l = l1 - 1; l >= 0; l--) {
        sum = sum + k * a[l];
        k = k * p;
      }
      if (sum >= 24) goto F1;
      sum = 0;
      k = 1;
      for (l = l2 - 1; l >= 0; l--) {
        sum += k * b[l];
        k *= p;
      }
      if (sum >= 60) goto F1;
    }
  F1:
    if (p == max + 1)
      cout << 0;
    else if (p >= 69)
      cout << -1;
    else {
      for (i = max + 1; i < p; i++)
        if (i == max + 1)
          cout << i;
        else
          cout << " " << i;
    }
    cout << endl;
  }
}
