#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1 << 60;
vector<int> ans;
bool check(string& a, string& b, int& d) {
  long long h = 0;
  for (int i = 0; i < ((int)(a).size()); ++i) {
    h *= d;
    if ('0' <= a[i] && a[i] <= '9') {
      h += a[i] - '0';
    } else {
      h += a[i] - 'A' + 10;
    }
    if (h > 23 || (a[i] >= 'A' && a[i] - 'A' + 10 >= d) ||
        (a[i] < 'A' && a[i] - '0' >= d)) {
      return 0;
    }
  }
  long long m = 0;
  for (int i = 0; i < ((int)(b).size()); ++i) {
    m *= d;
    if ('0' <= b[i] && b[i] <= '9') {
      m += b[i] - '0';
    } else {
      m += b[i] - 'A' + 10;
    }
    if (m > 59 || (b[i] >= 'A' && b[i] - 'A' + 10 >= d) ||
        (b[i] < 'A' && b[i] - '0' >= d)) {
      return 0;
    }
  }
  return 1;
}
int main() {
  string s;
  cin >> s;
  string a, b;
  bool fl = 0;
  for (int i = 0; i < ((int)(s).size()); ++i) {
    if (s[i] == ':') {
      fl = 1;
    } else if (!fl) {
      a += s[i];
    } else {
      b += s[i];
    }
  }
  for (int d = 2; d < 1000; ++d) {
    if (check(a, b, d)) {
      ans.push_back(d);
    }
  }
  if (((int)(ans).size()) > 500) {
    cout << "-1\n";
    return 0;
  }
  if (((int)(ans).size()) == 0) {
    cout << "0";
  }
  for (int i = 0; i < ((int)(ans).size()); ++i) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
