#include <bits/stdc++.h>
using namespace std;
bool test(string t, int base, int valmax) {
  int val = 0;
  for (int i = 0; i < t.size(); ++i) {
    val *= base;
    if ('0' <= t[i] && '9' >= t[i]) {
      if (t[i] - '0' >= base) return false;
      val += t[i] - '0';
    } else {
      if (t[i] - 'A' + 10 >= base) return false;
      val += t[i] - 'A' + 10;
    }
  }
  if (val > valmax) return false;
  return true;
}
int main() {
  string a[2];
  char t;
  int ind = 0;
  while (cin >> t) {
    if (t == ':') {
      ind++;
      continue;
    }
    a[ind].push_back(t);
  }
  for (int i = 0; i < 2; ++i)
    while (!a[i].empty() && a[i][0] == '0') a[i].erase(a[i].begin());
  vector<int> ans;
  for (int i = 1; i <= 61; ++i) {
    if (test(a[0], i, 23) && test(a[1], i, 59)) ans.push_back(i);
  }
  if (ans.size() == 0)
    cout << "0\n";
  else if (ans[ans.size() - 1] == 61)
    cout << "-1\n";
  else
    for (int i = 0; i < ans.size(); ++i)
      cout << ans[i] << " \n"[i == ans.size() - 1];
}
