#include <bits/stdc++.h>
using namespace std;
int main() {
  int flag1 = 0, flag2 = 0, j = 0, k = 0, ma = 0, end = 0;
  int a[5], b[5], i;
  vector<int> ans;
  string s;
  cin >> s;
  int lenth = s.size();
  for (i = 0; s[i] != ':'; i++) {
    if (flag1 == 0) {
      if (s[i] != '0') {
        flag1 = 1;
        if (s[i] <= '9' && s[i] >= '0')
          a[j++] = s[i] - '0';
        else
          a[j++] = s[i] - 'A' + 10;
        if (a[j - 1] != 0) ma = max(a[j - 1], ma);
      }
    } else {
      if (s[i] <= '9' && s[i] >= '0')
        a[j++] = s[i] - '0';
      else
        a[j++] = s[i] - 'A' + 10;
      if (a[j - 1] != 0) ma = max(a[j - 1], ma);
    }
  }
  i++;
  for (; i < lenth; i++) {
    if (flag2 == 0) {
      if (s[i] != '0') {
        flag2 = 1;
        if (s[i] <= '9' && s[i] >= '0')
          b[k++] = s[i] - '0';
        else
          b[k++] = s[i] - 'A' + 10;
        if (b[k - 1] != 0) ma = max(b[k - 1], ma);
      }
    } else {
      if (s[i] <= '9' && s[i] >= '0')
        b[k++] = s[i] - '0';
      else
        b[k++] = s[i] - 'A' + 10;
      if (b[k - 1] != 0) ma = max(b[k - 1], ma);
    }
  }
  if (j <= 1 && k <= 1) {
    if (a[0] <= 23 || j == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (i = ma + 1;; i++) {
    double temp = 0;
    for (int l = 0; l < j; l++) {
      temp += a[l] * pow((double)i, j - l - 1);
    }
    if (temp > 23) break;
    temp = 0;
    for (int l = 0; l < k; l++) {
      temp += b[l] * pow((double)i, k - l - 1);
    }
    if (temp > 59) break;
    end = i;
  }
  if (end == 0)
    cout << "0" << endl;
  else {
    for (i = ma + 1; i <= end; i++) cout << i << " ";
    cout << endl;
  }
  return 0;
}
