#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int a[5], b[5];
  while (getline(cin, str)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    int mid[60];
    memset(mid, 0, sizeof(mid));
    int len = str.length();
    int m = 0, n = 0;
    int i;
    int flag = 0;
    for (i = 0; str[i] != ':'; i++) {
      if (str[i] == '0' && !flag)
        continue;
      else {
        flag = 1;
        if (str[i] >= '0' && str[i] <= '9')
          a[m++] = str[i] - '0';
        else
          a[m++] = str[i] - 'A' + 10;
      }
    }
    flag = 0;
    i++;
    for (; i < len; i++) {
      if (str[i] == '0' && !flag)
        continue;
      else {
        flag = 1;
        if (str[i] >= '0' && str[i] <= '9')
          b[n++] = str[i] - '0';
        else
          b[n++] = str[i] - 'A' + 10;
      }
    }
    int ans;
    ans = a[0];
    for (i = 0; i < m; i++) {
      if (a[i] > ans) ans = a[i];
    }
    for (i = 0; i < n; i++) {
      if (b[i] > ans) ans = b[i];
    }
    ans += 1;
    if (n == 0 && m == 0) {
      cout << -1 << endl;
      continue;
    }
    if (n == 1 && m == 0) {
      cout << -1 << endl;
      continue;
    }
    if (n == 0 && m == 1) {
      if (a[0] < 24)
        cout << -1 << endl;
      else
        cout << 0 << endl;
      continue;
    }
    if (n == 1 && m == 1) {
      if (a[0] < 24)
        cout << -1 << endl;
      else
        cout << 0 << endl;
      continue;
    }
    int k = 0;
    int temp1, temp2, f1, f2;
    f1 = f2 = 0;
    temp1 = temp2 = 0;
    for (int j = 0; j < m; j++) temp1 = temp1 * ans + a[j];
    if (temp1 > 23) f1 = 1;
    for (int j = 0; j < n; j++) temp2 = temp2 * ans + b[j];
    if (temp2 > 59) f2 = 1;
    if (!f1 && !f2) mid[k++] = ans;
    for (i = ans + 1;; i++) {
      f1 = f2 = 0;
      temp1 = temp2 = 0;
      for (int j = 0; j < m; j++) {
        temp1 = temp1 * i + a[j];
      }
      if (temp1 > 23) f1 = 1;
      for (int j = 0; j < n; j++) temp2 = temp2 * i + b[j];
      if (temp2 > 59) f2 = 1;
      if (f1 || f2) break;
      mid[k++] = i;
    }
    cout << mid[0];
    for (i = 1; i < k; i++) cout << ' ' << mid[i];
    cout << endl;
  }
  return 0;
}
